重写bind方法

来源:互联网 发布:java isdirectory 编辑:程序博客网 时间:2024/06/05 02:57
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
原创粉丝点击