標籤:const asc this type func logs dev win define
<script type="text/javascript">(function (window,undefined){ function _$(arguments) { } _$.prototype={ constructor:_$, addEvent:function(){ alert("addEvent"); return this; }, getStyle:function(){ alert(‘getStyle‘); return this; } } window.$=_$; _$.onReady=function(fn){ window.$=function(){ return new _$(arguments); } fn(); }})(window)$.onReady(function(){ $("inq").addEvent().getStyle();})</script><script type="text/javascript">(function (window,undefined){ function _$(arguments) { } Function.prototype.method=function(methodName,fn) { this.prototype[methodName]=fn; return this; } _$.prototype={ constructor:_$, addEvent:function(){ alert("addEvent"); return this; }, getStyle:function(){ alert(‘getStyle‘); return this; } } window.$=_$; _$.onReady=function(fn){ window.$=function(){ return new _$(arguments); } _$.method(‘addEvent‘,function(){ alert("addEvent2"); return this; }).method(‘getStyle‘,function(){ alert("getStyle2"); return this; });fn(); }})(window)$.onReady(function(){ $("inq").addEvent().getStyle();}) //為什麼要加_$.method()? 不加也行?</script>
JS問題筆記——類比Jq底層實現原廠模式