call/apply
- call可以改变this的指向
- Person() --> Person.call();
- call里面的第一个参数是this的指向,后面按部就班的实参一一对应。
- apply 第一个参数是指向,第二个是arguements集合
function Person(name, age, sex){
this.name = name;
this.age = age;
this.sex = sex;
}
function Student(name, age, sex, tel, grade){
Person.call(this, name, age, sex);
this.tel = tel;
this.grade = grade;
}
var Student = new Student('sunny', 123, 'male', 139, 2017);
个人理解call/apply就是js实现多继承的方式一个类可以通过不断的改变this指向,达到继承多个类的目标