巧避new的一个原型设计模式

当我们勇气prototype的时候会发现必须要new  一下才能去调用,对此感觉又点小小不爽

下面在鬼群讨论的时候,一个群友提出了一个比较好的方法巧避new

下面就是一些主要代码:

var calendar=function(){
    return calendar['init'].apply(calendar,arguments)
}
(function(exports,global){
exports.init=function(){
    console.log(1)
}
exports.show=function(){
    console.log(2)
}
exports.getList=function(){
    console.log(3)
}
})(calendar,this)

这里直接调用对象而无需new 是不是很爽呢!!

posted @ 2013-04-17 10:55  黑暗骑士之“闪”  阅读(146)  评论(0编辑  收藏  举报