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

前端 未结 8 822
名媛妹妹
名媛妹妹 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:55

    This isn't unique to jQuery, but an aspect of javascript. All functions are objects. E.g.:

    var f = function() { alert('yo'); }
    f.foo = "bar";
    
    alert(f.foo); // alerts "bar"
    f();          // alerts "yo"
    

提交回复
热议问题