原来JavaScript的闭包概念是这样的

原来以为闭包是和内部函数有关系,这几天又重新看了JavaScript The Definitive Guide 5th.Edition,发现
8.8. Function Scope and Closures里是这么定义闭包的:

[quote]
JavaScript functions are a combination of code to be executed and the scope in which to execute them. This combination of code and scope is known as a closure in the computer science literature. All JavaScript functions are closures. These closures are only interesting, however, in the case discussed above: when a nested function is exported outside the scope in which it is defined. When a nested function is used in this way, it is often explicitly called a closure.
[/quote]

所以闭包其实就是一堆代码和某个scope组成的集合。我想称它为闭包的原因是因为在一个scope下的代码的执行都是封闭的(也就是说如果在不同的scope下执行相同的代码结果是不一样),不知道这样理解有没有问题。希望抛砖引玉了。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值