Function.prototype.myBind_3 = function() { let outContext = arguments[0] // 取上下文 let outArgs = Array.from(arguments).slice(1) // 取外部入参 const outThis = this // 存外部this let cb = function() { const isNew = typeof new.target !== 'undefined' // 判断函数是否被new过 const inArgs = Array.from(arguments)// 取内部入参 return outThis.apply(isNew ? this : outContext, outArgs.concat(inArgs)) // 改变指向,合并函数入参 } cb.prototype = outThis.prototype // 继承构造函数原型 return cb // 返回创建函数 }
标签:const,函数,outThis,bind,入参,arguments,cb,手写,prototype From: https://www.cnblogs.com/qingyanxd/p/17267147.html