题解 | #_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
 }

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务