Difference between jQuery.extend and jQuery.fn.extend?

前端 未结 5 729
醉话见心
醉话见心 2020-11-27 09:57

I am trying to understand the jquery plugin syntax, because I want to merge two plugins into one. The blinker that also needs to be able to stop de interval or run a number

5条回答
  •  天涯浪人
    2020-11-27 10:22

    This blog post have nice description:

    $.fn.extend({
    myMethod: function(){...}
    });
    //jQuery("div").myMethod();
    
    $.extend({
    myMethod2: function(){...}
    });
    //jQuery.myMethod2();
    

    Quotes:

    As a general rule, you should extend the jQuery object for functions and the jQuery.fn object for methods. A function, as opposed to a method, is not accessed directly from the DOM.

提交回复
热议问题