let myBind = function (fn, newThis) {
return function (...arg) {
let rndKey = [...Array(5)].map(_ => Math.random() * 1e17).join("-");
newThis[rndKey] = fn;
let result = newThis[rndKey](...arg);
delete newThis[rndKey];
return result;
}
}
let myfn = function (a) {
return (this.a + a);
}
console.dir(myfn(''));
myfn = myBind(myfn, { a: 2 });
console.dir(myfn(1));