1 2 3 4 5 6 7 8 9 10 11 12 13 14 | ( function (){
function Extend(func,proto){
func.prototype.__proto__=proto.prototype;
Object.defineProperty(func.prototype, "proto" ,{
value: proto.prototype
});
}
function Super(func,method){
if (!method) method='constructor';
return func.prototype.__proto__[method];
}
window.Extend=Extend;
window.Super=Super;
})();
|
ログイン後にコピー
スーパーのスーパーを処理中に無限ループが発生しました:
this.super-->this.proto.constructor(){this.super}-->this.proto.constructor。 。 。
その後、あまり複雑にしたくなかったので、上記のコードのメソッドを直接使用しました(知らなかっただけです...)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | ( function (){
function AAA(name){
this.name=name;
}
function BBB(name){
Super(BBB).call(this,name);
}
Extend(BBB,AAA);
function CCC(name,age){
Super(CCC).call(this,name);
this.age=age;
}
Extend(CCC,BBB);
var c= new CCC('ccc',18);
console.log(c);
})();
|
ログイン後にコピー
その後、関数を汚したくなかったので、窓を汚すことしかできませんでした。 。 。
関数の中に入れた方が簡単でしょうか?
りー