题目描述
封装函数 f,使 f 的 this 指向指定的对象
输入例子:
bindThis(function(a, b){return this.test + a + b}, {test: 1})(2, 3)
输出例子:
6
没什么好说的首先我们第一个返回值应该是一个函数,再然后在调用f是应该修改f的作用域.
function bindThis(f, oTarget) {
return function(a,b)
{
return f.call(oTarget,a,b);
}
}