call,apply,bind
计算机知识思维导图:call,apply,bind。网页展示前三层结构,可在线查看完整脑图并下载 GoMind 文件。
2026-08-25
## call,apply,bind ### call,apply,bind #### call ##### Untitled node ##### 示例 ##### 作用 #### apply ##### 示例 ##### 作用 #### bind ##### Untitled node ##### 作用 #### apply、call、bind 比较 ##### Untitled node ##### bind ##### call ##### apply #### 差异比较 ##### Untitled node ##### 调用关系 ##### 参数结构 ##### this指向改变的复用 ##### 柯里化实现 > 仅展示前三层结构;请在线查看完整脑图或下载 GoMind 文件。
call,apply,bind
call,apply,bind
Untitled node
functionObject.call( [ thisObj [, arg1 [, arg2 [, args...]]]] )
name = "张三";
age = 18;
function test(){
document.writeln(this);
document.writeln(this.name);
document.writeln(this.age);
};
// 全局函数内部的this默认为全局对象window
test(); // [object Window] 张三 18
var obj = {name: "李四", age: 20};
// 更改内部的this指针引用对象为obj
test.call(obj); // [object Object] 李四 20
function foo(a, b){
document.writeln(this.name);
document.writeln(a);
document.writeln(b);
}
// 改变this引用为obj,同时传递两个参数
foo.call(obj, 12, true); // 李四 12 true
function bar(a, b){
var o = {name: "王五"};
// 调用foo()函数,并改变其this为对象o,传入参数a,b作为其参数
foo.call(o, a, b);
}
bar("CodePlayer", "www.365mini.com"); // 王五 CodePlayer www.365mini.com示例
call()函数用于调用当前函数functionObject,使用thisObj作为执行时functionObject函数内部的this指针引用
作用
call
function cat() {
}
cat.prototype = {
food: "fish",
food2: "fish2",
say: function() {
alert("I love " + this.food+" " + this.food2);
}
}
var blackCat = new cat;
blackCat.say();// alert: I love fish fish2
var whiteDog = {food:"bone"};
blackCat.say.call(whiteDog);// alert: I love bone undefinedfunctionObject.apply( [ thisObj [, argsArray ]] )
name = "张三";
age = 18;
function test(){
document.writeln(this);
document.writeln(this.name);
document.writeln(this.age);
};
// 全局函数内部的this默认为全局对象window
test(); // [object Window] 张三 18
var obj = {name: "李四", age: 20};
// 更改内部的this指针引用对象为obj
test.apply(obj); // [object Object] 李四 20
function foo(a, b){
document.writeln(this.name);
document.writeln(a);
document.writeln(b);
}
// 改变this引用为obj,同时传递两个参数
foo.apply(obj, [12, true]); // 李四 12 true
function bar(){
var o = {name: "王五"};
// 调用foo()函数,并改变其this为对象o,传入当前函数的参数对象arguments作为其参数
foo.apply(o, arguments);
}
bar("CodePlayer", "www.365mini.com"); // 王五 CodePlayer www.365mini.com示例
apply()函数用于调用当前函数functionObject,使用thisObj作为执行时函数内部的this指针引用
作用
apply
Untitled node
Untitled node
同上call,apply 用于改变调用函数的this指向
与call,apply区别,bind并不会立即指向函数目标,仅声明this指向
call,apply是立即执行函数,而bind是提取改变this指向的对象,可多次使用
作用
bind
Untitled node
延迟调用
bind
立即调用
call
立即调用
apply
apply、call、bind 比较
bind
call
apply
Untitled node
延迟调用
立即调用
立即调用
调用关系
.bind(thisObj)()
.call( [ thisObj [, arg1 [, arg2 [, args...]]]] )
.apply( [ thisObj [, argsArray ]] )
参数结构
可复用
不可复用
不可复用
this指向改变的复用
yes
柯里化实现
差异比较