0

I know the difference between $.fn.extend and $.extend. But what is the difference between $.fn and $.fn.extend? When should I use one or the other? In the jQuery learning center for implementing jQuery plugins, I cannot find any examples that use $.fn.extend or discuss when to use $.fn.extend and when to use $.fn.

Thank you.

Take a very basic example:

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

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

$.fn.extend({
    greenifyP: function() {
        return this.css( "color", "green" );
    }
});

$(  "p" ).greenifyP();


// html
<a href="http://www.google.com">test</a>
<p>test</p>

Are the two methods exactly the same under the covers? I'm trying to determine when would I use $.fn.extend, as opposed to $.fn and if they are equivalent?

Elias Nicolas
  • 775
  • 13
  • 26
user3621633
  • 1,681
  • 3
  • 32
  • 46
  • 1
    Review this answer : http://stackoverflow.com/a/1991134/5365770 Or http://stackoverflow.com/a/13992290/5365770 – Diptox Sep 25 '15 at 01:11
  • Maybe start with what you are wanting to do. Assuming you want to put a plugin together. Can declare it several ways and will still do same thing – charlietfl Sep 25 '15 at 01:12
  • 1
    In other words .... *different strokes for different folks* – charlietfl Sep 25 '15 at 01:19

0 Answers0