Function.prototype.myBind = function(ctx, ...agrs1){
const fn = this;
function noopFn(){}
function innerFn(...args2){
ctx = this instanceof innerFn ? this : ctx;
const args = [...agrs1, ...args2];
const res = fn.apply(ctx, args);
return res;
}
noopFn.prototype = fn.prototype;
innerFn.prototype = new noopFn();
return innerFn;
}
Function.prototype.myApply = function(ctx, args){
ctx = ctx || window;
ctx.fn = this;
const res = ctx.fn(args);
delete ctx.fn;
return res;
}
Function.prototype.myCall = function(ctx, ...args){
ctx = ctx || window;
ctx.fn = this;
const res = ctx.fn(...args);
delete ctx.fn;
return res;
}