这里是原生js中bind的实现,我一些地方不是很理解,
if(!Function.prototype.bind){
Function.prototype.bind=function(obj){
var slice=[].slice,
args=slice.call.(arguments,1),
self=this,
nop=function(){},
bound=function(){
return self.apply(this, instanceof nop ? this:{obj||{}}),
args.concat(slice.call(arguments)))
};
nop.prototype=self.prototype;
bound.prototype=new nop();
return bound;
};
}
关于它的上下文是怎么变化的,我能够理解
但是我不太清楚,第一:
nop.prototype=self.prototype;
bound.prototype=new nop();
这里是在做什么?
第二是,这里的参数,关于参数数组的做法。
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
走同样的路,发现不同的人生