jQuery fn.extend ({bla: function(){}} vs. jQuery.fn.bla

前端 未结 2 772
孤街浪徒
孤街浪徒 2020-12-30 03:18

OK I think I get Difference between jQuery.extend and jQuery.fn.extend?

in that the general extend can extend any object, and that fn.extend is for plugin functions

2条回答
  •  无人及你
    2020-12-30 03:38

    There's very subtle difference between them. Performance wise (not that this is an issue), jQuery.fn.extend is going to be slower than directly declaring a function like jQuery.fn.foo = function(){ };. I'm talking completely negligible difference.

    The difference is jQuery.fn.extend() allows you to add multiple plugin functions simultaneously and might make your code look a little cleaner depending on what type of plugin you're authoring.


    jQuery.fn.a = function(){};
    jQuery.fn.b = function(){};
    

    Is exactly the same as

    jQuery.fn.extend({
      a: function(){ },
      b: function(){ }
    });
    

提交回复
热议问题