重写bind方法

一个新手
一个新手 原创
2017-09-20 10:11:34 940浏览


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

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。