12_Function.bind

本题考点:this、apply

根据题目要求,实现一个仿Function.bind功能的"Function._bind"函数,该函数会返回一个新的函数且该新函数内部通过apply修改了函数内部this指向,核心步骤有:

  1. 创建一个新this用来保存旧的this对象
  2. 返回一个匿名函数,该匿名函数返回通过apply修改了指针指向的函数运算结果

参考答案

Function.prototype._bind = function(target, ...arguments1) {
    const _this = this
    return function(...arguments2) {
        return _this.apply(target,arguments1.concat(arguments2))
    }
}