以下為JS寄生組合繼承的實現方式 function Super(b){
this.b = b;
this.fun = function(){}
}
Super.prototype.c = function(){console.log(1111)}
function Foo(a,b){
this.a = a;
Super.call(this,b);
}
var f = new Function();
f.prototype = Super.prototype;
Foo.prototype = new f();
var foo1 = new Foo(1,2);為什么不直接用以下方式,更簡潔而且能實現同樣的效果 function Super(b){
this.b = b;
this.fun = function(){}
}
Super.prototype.c = function(){console.log(1111)}
function Foo(a,b){
this.a = a;
Super.call(this,b);
}
Foo.prototype = Super.prototype;
var foo1 = new Foo(1,2);
JS寄生組合繼承的疑問
藍山帝景
2018-07-23 14:22:34