JavaScript继承写法
文章目录
构造函数+原型法
function person(name,age){
this.name = name;
this.age = age;
}
person.prototype.say = function(){
console.log(this.name+":"+this.age);
}
function superman(name,age){
person.call(this,name,age);
}
superman.prototype = new person();
superman.prototype.fight = function(){
this.say();
console.log("fighting...");
}
var s = new superman('superman',29);
s.fight();
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论