原理: https://blog.csdn.net/qq_40479190/article/details/78324270

示例: apply

 

Function.prototype.myApply = function(context) {
  let context = context || window
  context.fn = this
  let result
  if (arguments[1]){
    result = context.fn(...arguments[1])
  } else {
    result = context.fn()
  }
  delete context.fn
  return result
}

示例:call 

Function.prototype.myCall function (context){
    let context = context || window
    context.fn = this
    let args = [...arguments].slice(1)
    let result = context.fn(...args)
    delete context.fn
    return result
}