You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Function.prototype._bind=function(context){if(typeofthis!=='function'){throwError('Function.prototype._bind - what is trying to be bound is not callable')}varargs=Array.prototype.slice.call(arguments,1)varself=thisfunctionTmp(){}functionFbind(){args=args.concat(Array.prototype.slice.call(arguments))self.apply(thisinstanceofTmp ? this : context,args)}Tmp.prototype=this.prototypeFbind.prototype=newTmp()returnFbind}
模拟实现
bind
方法先来分析一下,我们自定义
bind
方法需要实现哪些功能this
的指向new
操作符调用,此时需要忽略传入的this参数1、第一个版本,返回一个绑定函数并且能够修改
this
的指向2、第二个版本,处理通过
new
调用返回的绑定函数参考
MDN bind
The text was updated successfully, but these errors were encountered: