javascript 代码 function person(name,age,job){ this.name=name; this.age=age; this.job=job; this.friends=[‘zl’,’foufou’]; } person.prototype={ constructor:person, sayname:function(){ alert(this.name); } } var p1=new person(‘zhanglin’,23,’it’); 组合继承 javascript 代码 function superType(name) { this.name = name; this.colors=[‘red’,’blue’,’green’]; } superType.prototype.sayname = function() { console.log(this.name) ; } function subType(name,age) { superType.call(this,name); this.age=age; } subType.prototype = new superType(); subType.prototype.sayage = function() { console.log(this.age) ; } var instance = new subType(‘zhanglin’,23); var stance = new subType(‘foufou’,23);
评论前必须登录!
注册