手写bind
Function.prototype.bind=function(ctx){
let fn = this;
if(!ctx){
ctx = typeof window !== 'undefined' ? window : global;
}
return function(...args){
ctx.fn=fn;
ctx.fn(...args)
}
}
function f(){
console.log(this.name);
}
var o = {name: 'o'};
var b = {name: 'b'};
f.bind(o)();
f.bind(b)();