js bind和call

bind和call都可以改变函数中的this 

function ab(x,y){
console.log(this);
console.log(x+y);
}

bind可以改变函数中的this并生成一个新的函数
var o={name:'jay'};
f=ab.bind(o,3,4);
f();

call可以直接调用函数

ab.bind(o,3,4);

猜你喜欢

转载自www.cnblogs.com/lac759/p/10556285.html