0

I'm starting to learn how to create a jquery plugin where the documentation recommend me to use $.fn

For example:

$.fn.greenify = function() {
    this.css( "color", "green" );
};

$( "a" ).greenify(); // Makes all the links green.

Then my question is, what is the advantage of using $.fn? Why can't I just assign a new variable to it and achieve the same result if they just want to be able to call that function like so:

var greenify = function() {
    this.css( "color", "green" );
};

$( "a" ).greenify(); // Makes all the links green.
Vincent1989
  • 1,593
  • 2
  • 13
  • 25

1 Answers1

0

In jQuery, the fn property is just an alias to the prototype property.

Look this: What does jQuery.fn mean?

Community
  • 1
  • 1
kosmos
  • 4,253
  • 1
  • 18
  • 36