Here is an alternate way to accomplish the same, if you feel unfamiliar with nested function calls.
好吧,如果你不太熟悉嵌套的函数调用,这是另一种写法。
What if we need to use a variable that is defined outside a nested function. Consider this contrived example.
那如果我们需要使用定义在嵌套函数外面的变量呢?考虑下面的例子。
When a nested function is used in this way, it is often explicitly called a closure.
当某个内嵌函数被这样使用时,它通常就被称作闭包。
Consider the following code, which includes a function that returns a nested function.
思考一下下面的代码,它包括一个能够返回内嵌函数的函数。
Things are different if you save a reference to the nested function in the global scope.
但如果你在全局作用域上保存了对内嵌函数的引用,事情就不一样了。
Things are different if you save a reference to the nested function in the global scope.
但如果你在全局作用域上保存了对内嵌函数的引用,事情就不一样了。
应用推荐