SOURCE

// 实现bind函数

Function.prototype.binds = function(context){
    const args = Array.prototype.slice(arguments,1);
    const self = this;
    return function (){
        const newArgs = Array.prototype.slice(arguments);
        const allArgs = newArgs.concat(args);
        return self.apply(context, allArgs)
    }
}

function add(){
    console.log(this.name)
}

const obj = {
    name: "taizi"
}

add();

add.binds(obj)();
console 命令行工具 X clear

                    
>
console