一共三种方法,call,apply,bind这三种方法都可以改变函数的this指向,但要注意bind绑定仅改变this指向,不会调用函数,故若想其调用,别忘了加().
function speak(fn, obj) {
//return fn.apply(obj);
//return fn.call(obj);
return fn.bind(obj)();
}
一共三种方法,call,apply,bind这三种方法都可以改变函数的this指向,但要注意bind绑定仅改变this指向,不会调用函数,故若想其调用,别忘了加().
function speak(fn, obj) {
//return fn.apply(obj);
//return fn.call(obj);
return fn.bind(obj)();
}