Javascript如何实现继承
作者:
飞飞廉 | 来源:发表于
2018-03-06 11:35 被阅读0次
function Person(name){
this.name=name;
}
function Child(){
Person.call(this,'wang')
this.age=16
}
var man=new Child();
console.log(man.name,man.age)
function Person(name){
this.name=name;
}
Person.prototype.sayName=function(){
alert(this.name)
}
function Child(name,age){
Person.call(this,name);
this.age=age;
}
Child.prototype=new Person();
Child.prototype.constructor=CHild;
var instance=new Child('lisi',18)
本文标题:Javascript如何实现继承
本文链接:https://www.haomeiwen.com/subject/whulfftx.html
网友评论