题解 | #_call函数#
_call函数
https://www.nowcoder.com/practice/22df1ed71b204a46b00587fdb780b3ab
Function.prototype._call = function (context, ...args) {
// 判断context,如果为null或者undefined,直接指向window
let cxt = context || window;
// 新建一个唯一的Symbol,避免重复
let func = Symbol();
cxt[func] = this;
args = args ? args : [];
// 以对象的方式调用func,此时的this为传入需要绑定的this指向
const res = args.length > 0 ? cxt[func](args) : cxt[func]();
// 删除方法,避免对全局造成污染
delete cxt[func];
return res;
};

查看16道真题和解析