先展示个例子:
var Person = function(name){
this.name = name;
};
Person.prototype = {
constructor:Person,
id:100
};
var Boy = function(name,sex,age){
Person.call(this,name);
this.sex = sex;
this.age = age;
};
详解:call()是将Person的属性绑定到当前(this也就是Boy)方法中,让其拥有相同的属性;
语法:
fun.call(thisArg, arg1, arg2, ...)