SOURCE

Function.prototype.bind = Function.prototype.bind || function(thisArg) {
    if (typeof this !== 'function') {
        throw new Error('bind must be called by function');
    }
    var context = this;
    var args = Array.prototype.slice.call(arguments, 1);
    var bound = function() {
        var thisArgs =  this instanceof Foo ? this : thisArg;
        return context.apply(thisArgs, args.concat(Array.prototype.slice.call(arguments)));
    }
    var Foo = function() {};
    // 处理剪头函数
    if (this.prototype) {
        Foo.prototype = this.prototype;
    }
    bound.prototype = new Foo();
    return bound;
}


function a() {
    console.log(1);
}
a.bind(this, '2', '3');
console 命令行工具 X clear

                    
>
console