Loading

手写原生函数

手写 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;
}
posted @ 2023-05-17 11:41  mx羽林  阅读(5)  评论(0编辑  收藏  举报