当前位置:Gxlcms > JavaScript > 重写bind方法

重写bind方法

时间:2021-07-01 10:21:17 帮助过:42人阅读


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方法的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行