What does fn mean when used in Raphael?

I have seen fn use in raphael, which is a javascript lab.

Raphael.fn.g.piechart = function (cx, cy, r, values, opts) {
  // blah...blah
}

it extends raphael, so people can use it as r = Raphael; rgpiechart.

I searched google and don’t understand anything like me. hope you can help.

+3
source share
6 answers

fnused to add custom methods to the canvas .

Any methods that you add to fnwill work on the canvas. This contrasts with methods that will work on for example an element (for which you would use ). el

fn , Raphael ( , el ).

, :

  // Extend Raphael fn object by adding methods to it:
Raphael.fn.arrow = function (x1, y1, x2, y2, size) {
    return this.path( ... );
}; 
  // or add namespaces to it:
Raphael.fn.mystuff = {
    arrow: function () {…},
    star: function () {…},
    // etc…
};

  // Now when you create a Raphael instance, your custom
  // methods are available.
var paper = Raphael(10, 10, 630, 480);

  // Using custom methods:
paper.arrow(10, 10, 30, 30, 5).attr({fill: "#f00"});

  // Using name spaced custom methods
paper.mystuff.arrow();
paper.mystuff.star();

( AleksandraKos):

, Raphael 2.0

+8

, Raphael, :

Raphael.fn = {};

, , .

+3

.

, Raphael , .

, .

jQuery $.fn.

+2

JS-. , - , , fn , foo myVariable. jQuery, , jQuery.fn === jQuery.prototype ( ).

+2
+1

fn JavaScript.

+1

Source: https://habr.com/ru/post/1769104/


All Articles