jQuery.extend default action with only one input
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();
};
精彩评论