讨论三种常用的继承方式:
- 组合继承
function Fn(name){
this.name = name;
}
Fn.prototype.getName = function(){
return this.name;
}
var fn = Fn(name){
Fn.call(this, name);
}
- 原型新对象继承
fn.prototype = Object.create(Fn.prototype)
3 . 寄生继承
function Gn(pro){
var Tn = {};
Tn.prototype = pro;
return Tn;
}
fn.prototype = Gn(Fn.prototype);
网友评论