举个例子
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就用于了所有的属性和方法
本文通过实例演示如何使用JavaScript中的call()方法在特定作用域下调用函数,并详细解释了对象属性和方法的使用。
举个例子
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就用于了所有的属性和方法
947
1311
1万+
672
327

被折叠的 条评论
为什么被折叠?