题解 | #修改 this 指向#
修改 this 指向
https://www.nowcoder.com/practice/a616b3de81b948fda9a92db7e86bd171
function bindThis(f, oTarget) {
//apply传入的参数是数组形式传入,立即执行需要写function()
return function(){
return f.apply(oTarget,arguments)
}
}
function bindThis(f,oTarget){
//和call一样,但是返回的是函数,需要调用才执行
return f.bind(oTarget)
}
function bindThis(f,oTarget){
//后面的参数一个个传入,立即执行需要写function()
return function(){
return f.call(oTarget,...arguments)
}
}