How does jQuery makes the jQuery object both a function and an object property?

后端 未结 3 354
被撕碎了的回忆
被撕碎了的回忆 2020-12-06 05:23

I\'ve been wondering for a long time how jQuery can be both a function and an object property.

You can use it like a function, jQuery(...) and you can use it like a

3条回答
  •  借酒劲吻你
    2020-12-06 06:29

    functions are objects in javascript. So you can have your main function

    var $ = function() {  alert('wat'); }
    

    and then extend it

    $.fadeTo = function() { alert('fadeto'); }
    

提交回复
热议问题