何千番煎じか分からんけど、こんなんを定義する。
Function.prototype.extend = function (Class){
var f = function (){};
f.prototype = Class.prototype;
this.prototype = new f()
this.prototype.__super__ = Class.prototype;
this.prototype.__super__.constructor = Class;
this.prototype.constructor = this;
};
こんな感じで使う。
var BaseClass = function(){
this.init.apply(this, arguments);
};
BaseClass.prototype.init = function(){
console.log("base init");
};
var ExClass = function(){
this.init.apply(this, arguments);
};
ExClass.extend(BaseClass);//継承する
ExClass.prototype.init = function(){
this.__super__.init();
console.log("ex init");
};
//
new ExClass();
やってることは継承というかmixinか。
Stateパターンとかやる場合重宝する。