手写bind函数

Function.prototype.myBind = function () {
  // 吧arguments转数组
  let args = Array.prototype.slice.call(arguments)
  let first = args.shift()
  // this就是调用函数本身
  let _this = this
  return function () {
    return _this.apply(first, args)
  }
}
function func1 (a, b, c) {
  console.log('this', this);
  return a + b + c
}
const a = func1.myBind(233, 'www', 'baidu', 'com')
console.log(a())

results matching ""

    No results matching ""