手撕call、apply、bind
Funtion.prototype.call_ = (target, ...arguments) => {
target = target || window;
const symbolKey = Symbol();
target[symbolKey] = this;
const res = target[symbolKey](...arguments);
delete target[symbolKey];
return res;
}
Function.prototype.apply_ = (target, arguments) => {
target = target || window;
const symbolKey = Symbol();
target[symbolKey] = this;
const res = target[symbolKey](...arguments);
delete target[symbolKey];
return res;
}
Function.prototype.bind_ = (target, arguments) => {
target = target || {};
const symbolKey = Symbol();
return function(rest) {
target[symbolKey] = this;
const res = target[symbolKey](...argyments, ...rest);
delete target[symbolKey];
return res;
}
}