# Call
Function.prototype.call = (context = window) => {
context.fn = this
const args = [...arguments].slice(1)
const res = context.fn(...args)
delete context.fn
return res
}
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# Apply
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;
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14