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

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

    Javascript is an object oriented language, so functions ARE objects, just fancy ones that you can call.

    foo = function() { console.log("foo") }
    foo.bar = function() { console.log("bar") }
    foo() //=> prints "foo"
    foo.bar() //=> prints "bar"
    

提交回复
热议问题