开发者

jQuery.extend default action with only one input

开发者 https://www.devze.com 2023-01-17 01:51 出处:网络
Given: jQuery.extend({ fooBar: function(){ return \'baz\'; } })开发者_StackOverflow; does it modify the base jQuery object?

Given:

jQuery.extend({
  fooBar: function(){ return 'baz'; }
})开发者_StackOverflow;

does it modify the base jQuery object? so afterwards you can call jQuery.fooBar(); // 'baz'

There's nothing in the documentation, but that's what the source does as far as I can tell.


The behavior is documented right here: http://api.jquery.com/jQuery.extend/

If only one argument is supplied to $.extend(), this means the target argument was omitted. In this case, the jQuery object itself is assumed to be the target. By doing this, we can add new functions to the jQuery namespace. This can be useful for plugin authors wishing to add new methods to JQuery.


Yes I believe that is correct. Similarly, if you want to be able to call $(somejQueryObject).fooBar(); you can do this

$.fn.fooBar = function() {
    return $.fooBar();
};
0

精彩评论

暂无评论...
验证码 换一张
取 消