var that = null;
Function.prototype.bind = function(obj,arg){
if (that == null){
that = this
}
return function(){
return that.call(obj,arg);
}
};
function foo() {
return this.bar;
}
foo = foo.bind({bar:1});
foo = foo.bind({bar:2});
var result = foo();
console.log(result);//2
重写bind方法
最新推荐文章于 2021-07-25 11:11:15 发布