Skip to main content

call

Function.prototype.myCall = function (context = window, ...args) {
context = context || window // 参数默认值并不会排除null,所以重新赋值
context.fn = this // this是调用call的函数
const result = context.fn(...args)
delete context.fn // 执行后删除新增属性
return result
}