Javascript如何实现继承?

1、构造继承2、原型继承3、实例继承4、拷贝继承
 
原型prototype机制或apply和call方法去实现较简单,建议使用构造函数与原型混合方式。
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);//得到被继承的属性

.

posted @ 2019-09-25 23:19  每天都要进步一点点  阅读(157)  评论(0编辑  收藏  举报