所谓JavaScript构造函数继承,大概就是使用call()或apply()方法,将父对象的构造函数绑定在子对象上,从而实现子对象的继承。
代码如下:
//父类 function Person(){ this.species = '人类'; } //子类 function Programmer(age,gender,skill){ Person.apply(this, arguments); this.age = age; this.gender = gender; this.skill = skill; } var ap = new Programmer(25,'男','javascript'); console.log(ap.species);// "人类"
这种继承方式为觉得挺好的。