首页 新闻 会员 周边

为什么要delete context.fn

0
悬赏园豆:10 [已解决问题] 解决于 2020-10-15 10:01

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

delete context.fn这一步的意义是什么,有什么好处吗?

纯海之蓝的主页 纯海之蓝 | 初学一级 | 园豆:132
提问于:2020-09-09 13:48
< >
分享
最佳答案
0

如果没有那一步的话
那么当你调用 myApply() 之后
fn 这个方法就会留在调用的对象上
这显然是不对的

收获园豆:10
by.Genesis | 老鸟四级 |园豆:2719 | 2020-09-11 23:39
其他回答(1)
0

按我的理解应该是把分配的内存给释放掉

不知道风往哪儿吹 | 园豆:2035 (老鸟四级) | 2020-09-09 15:39
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册