[code type='javascript']
//1
(function(){
window.Me=function(){
return Me.fn.init();
};
Me.fn= Me.prototype={
showname:function(){
alert(11);
},
showage:function(){
alert(22);
},
init:function(){
return this;
}
}
})();
Me().showname();
//2
(function(){
window.Me=function(){
return new Me.fn.init();;
};
Me.fn= Me.prototype={
showname:function(){
alert(11);
},
showage:function(){
alert(22);
},
init:function(){
return this;
}
}
})();
Me().showname();
[/code]
//1 段代码执行正确
//2 出错调试中发现, return new Me.fn.init(); 返回的是 Me.fn.init 的实例,而不是Me.fn,因此怎么能调用这个{}json对象里面定义的方法呢?
果然//2的Me().showname();方法出错.但是看了jquery的源码 也是这样的. return new jQuery.fn.init( selector, context );这很让我费解.... 求帮助..................
//1
(function(){
window.Me=function(){
return Me.fn.init();
};
Me.fn= Me.prototype={
showname:function(){
alert(11);
},
showage:function(){
alert(22);
},
init:function(){
return this;
}
}
})();
Me().showname();
//2
(function(){
window.Me=function(){
return new Me.fn.init();;
};
Me.fn= Me.prototype={
showname:function(){
alert(11);
},
showage:function(){
alert(22);
},
init:function(){
return this;
}
}
})();
Me().showname();
[/code]
//1 段代码执行正确
//2 出错调试中发现, return new Me.fn.init(); 返回的是 Me.fn.init 的实例,而不是Me.fn,因此怎么能调用这个{}json对象里面定义的方法呢?
果然//2的Me().showname();方法出错.但是看了jquery的源码 也是这样的. return new jQuery.fn.init( selector, context );这很让我费解.... 求帮助..................
http://bbs.blueidea.com/thread-2977915-1-1.html
蓝色理想看我在那发的贴