SOURCE

Function.prototype.mybind=function(context){
    if(typeof this !== 'function'){
        throw new Error("n a f");
    }
    if(typeof context ==null ||typeof context ==undefined ){
        context =window;
    }
    context.fn = this;
    let args = Array.from(arguments).slice(1);
    return function(){
        let newArgs = args.concat(Array.from(arguments));
        //注意concat不会原数组,只会返回新数组
        let res = context.fn(...newArgs);
        return res;
    }
    //提醒一个点:typeof的返回值全是小写字母
}

function me(){
    console.log(this);
}
let o1={a:1,name:'o1'};
let o2 = {a:2,name:'o2'};
me.mybind(o2)();


console 命令行工具 X clear

                    
>
console