jQuery的无new构建
生活随笔
收集整理的這篇文章主要介紹了
jQuery的无new构建
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
var aQuery = function(selector, context) {return new aQuery.prototype.init();
}
aQuery.prototype = {init: function() {return this;},name: function() {return this.age},age: 20
}
aQuery.prototype.init.prototype = aQuery.prototype; //主要靠這句話起作用。(aQuery.prototype.init).prototype = aQuery.prototype;這樣就更明顯了。避免了new的init跟jquery類(lèi)的this分離
console.log(aQuery().name()) //20
console.log(aQuery().name()) //20
var $ = function(){
return new $.prototype.init();
}
$.prototype = {
init:function(){
console.log("init");
return this;
},
age:function(){
console.log("age");
return this;
},
name:function(){
console.log("name");
return this;
}
}
$.prototype.init.prototype = $.prototype;
console.log($().age().name().init());
轉(zhuǎn)載于:https://www.cnblogs.com/yuan-ye/p/4815346.html
總結(jié)
以上是生活随笔為你收集整理的jQuery的无new构建的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: POST单文件上传
- 下一篇: Firebug的安装方法