举个例子
var Human(name,age){
this.name = name;
this.age = age;
this.sayName = function(){
alert(this.name);
}
}
Human.call(o,"张三","20");
o.sayName();//返回“张三”
call()方法是在某个特殊对象作用域中调用Human()函数,这里是o的作用域,所以o就用于了所有的属性和方法
举个例子
var Human(name,age){
this.name = name;
this.age = age;
this.sayName = function(){
alert(this.name);
}
}
Human.call(o,"张三","20");
o.sayName();//返回“张三”
call()方法是在某个特殊对象作用域中调用Human()函数,这里是o的作用域,所以o就用于了所有的属性和方法