题解 | #_call函数#
_call函数
https://www.nowcoder.com/practice/22df1ed71b204a46b00587fdb780b3ab
Function.prototype._call = function(thisArg,...args) { // 1.获取目标函数 var fn = this // 2.将thisArg转换为对象类型,避免传入的是非对象类型 thisArg = (thisArg !== null && thisArg !== undefined) ? Object(thisArg):window // 3.执行函数 thisArg.fn = fn var res = thisArg.fn(...args) delete thisArg.fn // 4.返回结果 return res }