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.bind(thisArg[, arg1[, arg2[, ...]]])
返回一个原函数的拷贝,并拥有指定的 this 值和初始参数。
对于普通函数,绑定this指向
对于构造函数,要保证原函数的原型对象上的属性不能丢失
Function.prototype.mybind=function(context, ...args){if(typeofthis!=='function'){thrownewError("this is not a function")}letself=thisletFB=function(){self.apply(//当为普通函数的时候 this 指向window,self指向绑定函数 为 false,this为绑定的实例对象//当为构造函数的时候 this 指向实例,self指向绑定函数 为 true,this为new出来的实例对象thisinstanceofself ? this : context,args.concat(Array.prototype.slice.call(arguments)))}FB.prototype=Object.create(this.prototype)returnFB}
The text was updated successfully, but these errors were encountered:
API
function.bind(thisArg[, arg1[, arg2[, ...]]])
返回一个原函数的拷贝,并拥有指定的 this 值和初始参数。
The text was updated successfully, but these errors were encountered: