参考:http://ejohn.org/blog/simple-class-instantiation/
本文介绍了一种简单的JavaScript类实例化方法。这种方法使用了一个init函数来代替构造函数,并且使用了原型链来继承属性和方法。此外,该方法还可以方便地创建子类。// makeClass - By John Resig (MIT Licensed)
function makeClass(){
return function(args){
if ( this instanceof arguments.callee ) {
if ( typeof this.init == "function" )
this.init.apply( this, args.callee ? args : arguments );
} else
return new arguments.callee( arguments );
};
}
我在想,是否有任何符合ECMAScript 5标准的方法来实现相同的功能。问题是,在严格模式下访问arguments.callee
已被弃用。