Home  >  Article  >  Web Front-end  >  Override bind method

Override bind method

一个新手
一个新手Original
2017-09-20 10:11:341284browse


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

The above is the detailed content of Override bind method. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn