JS问题笔记——模拟Jq底层实现工厂模式

<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>
上一篇:原型工具之团队协作: Axure VS Mockplus


下一篇:[持续交付实践] 研发协作平台:DevOps背景下的组织结构