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.
1
  • Because a function is not a method. Notice that .fn is an alias for .prototype. Commented Apr 22, 2015 at 11:14

1 Answer 1

0

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

Look this: What does jQuery.fn mean?

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.