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

前端 未结 5 704
醉话见心
醉话见心 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条回答
  •  -上瘾入骨i
    2020-11-27 10:16

    jQuery.extend is used to extend any object with additional functions, but jQuery.fn.extend is used to extend the jQuery.fn object, which in fact adds several plugin functions in one go (instead of assigning each function separately).

    jQuery.extend:

    var obj = { x: function() {} }
    
    jQuery.extend(obj, { y: function() {} });
    
    // now obj is an object with functions x and y
    

    jQuery.fn.extend:

    jQuery.fn.extend( {
            x: function() {},
            y: function() {}
    });
    
    // creates 2 plugin functions (x and y)
    

提交回复
热议问题