浏览 1831 次
锁定老帖子 主题:原来JavaScript的闭包概念是这样的
精华帖 (0) :: 良好帖 (0) :: 新手帖 (3) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2009-04-20
8.8. Function Scope and Closures里是这么定义闭包的: 引用 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. 所以闭包其实就是一堆代码和某个scope组成的集合。我想称它为闭包的原因是因为在一个scope下的代码的执行都是封闭的(也就是说如果在不同的scope下执行相同的代码结果是不一样),不知道这样理解有没有问题。希望抛砖引玉了。 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2009-04-30
看来大家都很清楚了 汗
|
|
返回顶楼 | |
发表时间:2009-05-05
Jquery的作者John也会大量的时间才完全理解闭包的强大的概念。
所以并不会因为看了这么几句闭包的定义,你就理解了闭包!!! |
|
返回顶楼 | |