题解 | #修改 this 指向#
修改 this 指向
https://www.nowcoder.com/practice/a616b3de81b948fda9a92db7e86bd171
function bindThis(f, oTarget) { //封装函数 f,使 f 的 this 指向指定的对象. //记得封装 return function(){} //可以用call()、apply()、bind(),其中arguments为参数列表 return function(){ return f.apply(oTarget, arguments); //需把局部变量arguments参数传到函数中,so不可省。apply的第二个参数是数组。 } return function(){ return f.call(oTarget, ...arguments); }/**/ return f.bind(oTarget); //本身返回的是一个函数,so 参数可省。 }