js 笔试题 多次bind重写

function foo() {

    return this.bar;

}

foo = foo.bind({bar:1});

foo = foo.bind({bar:2});

foo();

要让这里的foo()输入2,我的答案是:


Function.prototype.bind = function(obj,arg){

    var that = this;

    return function(){

     return that.call(obj,arg);

    }

};

function foo() {

    return this.bar;

}

foo = foo.bind({bar:1});

foo = foo.bind({bar:2});

foo();

然而输出1


慕容森
浏览 416回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript