我们知道javascript的继承方式只能通过自己来实现,网上流传了许多的版本,常见的版本如下
function Parent(){
this.gogogo = {};
this.name = 'hehe';
}
Parent.prototype = {
};
function Child(){
}
Child.prototype = new Parent();
我们知道,在实例化一个对象的时候,经常需要传几个参数给构造方法,然后在构造方法里初始化一些东西
那么这种继承就无法实现,例子
function Student(info) {
var details = info.split('|');
this.name = details[0];
this.sex = details[1];
}
function LevelStudent(info) {
this.level = '三年级'
this.callded = this.level+this.name;
}
LevelStudent.prototype = new Student();
var xiaoMing = new LevelStudent('小明|1');
运行之后肯定直接报错了
所以这种继承 无法使用参数这个在继承里可以说是非常致命的