Home > Web Front-end > JS Tutorial > body text

Override bind method

一个新手
Release: 2017-09-20 10:11:34
Original
1333 people have browsed it


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
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template