This is your first opportunity to use function closures to enclose variables in function definitions, but it won't be the last, so get used to this, too.
这是使用函数闭包在函数定义中封闭变量的第一种方法,但不是惟一的方法,目前就采用这种方法。
Closures are powerful because they enable inner functions to retain access to an outer function's variables even after the outer function has returned.
闭包功能非常强大,原因是它们使内部函数在外部函数返回时也仍然可以保留对此外部函数的变量的访问。
Closures are function literals - expressions that embody a deferred computation that can be treated as a value and invoked later.
闭包是函数字面量(unction literal)——是包含了一个递延计算的表达式,该计算可被当成值对待,在晚些时候再调用。
Before closures, implementation of the passed function was limited to the context of its function arguments.
在closures之前,对所传递函数的实施限定在其函数参数的上下文。
As we saw in the examples for lambda functions, one of the most obvious USES for closures is in the few PHP functions that accept a callback function as a parameter.
如在lambda函数的示例中所示,闭包的最明显用法之一是少数php函数接受回调函数作为参数。
It does include support for closures (which are essentially functions that can reference state in another function).
它支持闭包(实质上是可以在另一个函数中引用状态的函数)。
Using closures serves the same purpose in this situation as it would outside of a class: to contain a specific function to be bound within a small scope.
在这种情况下使用闭包与在类外部使用闭包实现的目的相同:包含在小范围内绑定的特定函数。
Closures are functions that reference variables from the scope enclosing the function definition.
闭包本质上是一个函数和其引用的变量的统一定义。
The concept of lambda functions is the basis for closures and provides a much-improved way to create functions on the fly vs. the create_function function already in PHP.
lambda函数的概念是闭包的基础,并且提供了一种比PHP中已有的create_function函数改进了很多的动态创建函数的方法。
The above example is a good use case for closures: It USES one of the 18 standard PHP array functions that take a function as a parameter (such as array_walk, usort, and array_app).
以上示例是closures很好的使用例子:它采用18个标准php阵列函数之一,它将函数作为参数(比如array_walk、usort、和array_app)。
Function literals and the related concept of a closure are discussed in the section called "Function literals and Closures" in Chapter 8, Functional Programming in Scala.
字面函数和闭包相关的概念会在《第8章-scala函数式编程》的“字面函数和闭包”章节中被讨论。
When more than one inner function exists, closures can have effects that are not as easy to anticipate.
当有一个以上的内部函数时,闭包产生的效果可能没有预期所想像的那样简单。
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.
然后这些闭包只在上面讨论的这些情形下才显得有趣:当某个内嵌函数被暴露在它所被定义的作用域外时。
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.
然后这些闭包只在上面讨论的这些情形下才显得有趣:当某个内嵌函数被暴露在它所被定义的作用域外时。
应用推荐