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

前端 未结 8 853
名媛妹妹
名媛妹妹 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 09:02

    var q=function(){};
    
    var s = function(){
        alert("base");
        window.s = s;
        return new q()};
    
    q.fn = q.prototype = {};
    
    q.fn.x = s.x = function(){alert("x");return this;};
    q.fn.y = s.y = function(){alert("y");return this;};
    q.fn.z = s.z = function(){alert("z");return this;};
    
    s().y().z().x();
    s.z().x().y();
    

提交回复
热议问题