Function.prototype.bind实现

2019-01-20  本文已影响0人  一只重拾梦想的小水

Function.prototype.bind=function(that, rest){

const outterThis = this;

return function(){

const innerThis = outterThis;

Array.prototype.splice.call(arguments, 0, rest.length, ...rest)

innerThis.apply(that, arguments)

}

}

Function.prototype.bind=function(that, rest){

return (...argu)=>{

argu.splice(0, rest.length, ...rest)

this.apply(that, argu)

}

}

上一篇下一篇

猜你喜欢

热点阅读