How is jQuery's $ a function and an object?

前端 未结 8 816
名媛妹妹
名媛妹妹 2020-11-29 08:22

I mean object as in {} [object Object]. How does it do $(selector) and $.fn.init at the same time?

Can you give me a simple ex

8条回答
  •  自闭症患者
    2020-11-29 08:53

    It is an object.

    $ holds different functions.

    You can test this yourself by making your own object:

    var $ = {
         select: function(id){return document.getElementById(id);}
    }
    
    function $(id){
          return $.select(id);
    }
    

提交回复
热议问题