Disclaimer: This article is a blogger original article, follow the CC 4.0 BY copyright agreement, reproduced, please attach the original source link and this statement.
How Javascript implementation inheritance?
1, the configuration of inheritance
2, prototype inheritance
3, inheritance Example
4, copy inheritance
Apply and call mechanism or method to achieve relatively simple prototype prototype, prototype recommended constructor and mixed mode.
function Parent(){
this.name = 'wang';
}
function Child(){
this.age = 28;
}
Child.prototype = new Parent();//继承了Parent,通过原型
var demo = new Child();
alert(demo.age);
alert(demo.name);//得到被继承的属性
JavaScript inheritance of several implementations?
- reference:
- Inherited constructor function ,
- Non-inherited constructor ;