构造函数继承

构造函数继承

①使用call或apply方法,将父对象的构造函数绑定在子对象上,即在子对象构造函数中加一行

Animal.apply(this, arguments);===>构造函数绑定

②使用prototype属性

Cat.prototype = new Animal();
Cat.prototype.constructor = Cat;

③直接继承prototype

function Animal(){ }
Animal.prototype.species = "动物";

④利用空对象作为中介

⑤拷贝继承

这个函数的作用,就是将父对象的prototype对象中的属性,拷贝给Child对象的prototype对象。

猜你喜欢

转载自570109268.iteye.com/blog/2354375