js手写一个apply

js手写一个apply
/**
 * 手写一个apply方法
 * 函数名字为 myApply
 * symbol优化
 */
Function.prototype.myApply = function (targetObj, args) {
  // symbol优化
  let key = Symbol('keys')
  targetObj[key] = this
  let resus = targetObj[key](...args)
  delete targetObj[key]
  return resus
}
posted @ 2023-10-14 21:30  jialiangzai  阅读(45)  评论(0)    收藏  举报