我已经知道了,apply
并且call
是类似的函数集this
(函数的上下文)。
区别在于我们发送参数的方式(手动vs数组)
题:
但是什么时候应该使用该 bind()
方法?
var obj = {
x: 81,
getX: function() {
return this.x;
}
};
alert(obj.getX.bind(obj)());
alert(obj.getX.call(obj));
alert(obj.getX.apply(obj));
I think the same places of them are: all of them can change the this value of a function.The differences of them are: the bind function will return a new function as a result; the call and apply methods will execute the function immediately, but apply can accept a array as params,and it will parse the array separated.And also, the bind function can be Currying.