简体   繁体   中英

jQuery.extend default action with only one input

Given:

jQuery.extend({
  fooBar: function(){ return 'baz'; }
});

does it modify the base jQuery object? so afterwards you can call jQuery.fooBar(); // 'baz' 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();
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM