您的位置:首页 > 其它

寄生组合式继承

2014-10-07 15:11 197 查看
function suber (name) {
this.name=name;
this.frend=["xx","yy"];
}
suber.prototype.sayName = function() {
alert(this.name);
};
function sub(name,age){
suber.call(this,name);
this.age=age;
}
function inheritPrototype (sub,suber) {
var prototype=Object(suber.ptototype);
prototype.constructor=sub;
sub.prototype=prototype;
}
inheritPrototype(sub,suber);
sub.prototype=new suber();
sub.prototype.sayName = function() {
alert(this.name+"xxxxxxxxx");
};
var su=new sub("sun zi",33);
su.frend.push(33);
// alert(su.frend.toString());
var suber=new suber("lao zi");
su.sayName();
suber.sayName()
// alert(suber.frend.toString()+"=  "+suber.sayName());
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: