手写原生函数

发布时间 2023-05-17 11:43:10作者: mx羽林

手写 Function.prototype.call:

Function.prototype.myCall = function (context, ...args) {
  context = context || window;
  const fn = Symbol('fn');
  context[fn] = this;
  const result = context[fn](...args);
  delete context[fn];
  return result;
}