call && apply
Function.prototype.call = (context = window) => {
context.fn = this
const args = [...arguments].slice(1)
const res = context.fn(args)
delete context.fn
return res
}
Function.prototype.apply = (context = window, ...args) => {
context.fn = this;
let res;
if (args.length) {
res = context.fn(args);
} else {
res = context.fn();
}
delete context.fn;
return res;
};