字面函数和闭包相关的概念会在《第8章-scala函数式编程》的“字面函数和闭包”章节中被讨论。
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.
这种情况下返回的函数对象就是一个闭包,其中封装了一些日志代码和最初的函数调用所需要的数据。
In this case the returned function object is a closure which encapsulates some logging code and the data needed to call the original function.
在本文中,我将继续讨论这些概念,讲解一级函数、优化和闭包。
In this article, I'll continue this tour of concepts by talking about first-class functions, optimizations, and closures.
这个闭合的作用域是将闭包同调用函数和定义它的代码联系起来的纽带。
This closed scope is the communication that ties the closure to the calling function and the code that defines it.
我们还在闭包内获取狗的颜色和名字,传递到构造函数中并存储到对象中。
We also grab the color and name of the dog, passed in the constructor and stored in the object, within the closure.
要完全支持闭包,这种语言必须支持在运行时操纵、调用和创建函数,还要支持函数可以捕获创建这些函数的环境。
To support closures fully, a language needs to provide support for manipulating, invoking, and creating functions at run time and for functions to capture the environment in which they were created.
闭包本质上是一个函数和其引用的变量的统一定义。
Closures are functions that reference variables from the scope enclosing the function definition.
正如我们所见,反射API能够通过现有函数和方法动态创建闭包,从而为闭包提供强大的支持。
The reflection API has great support for closures, as we've now seen, in the form of being able to create them from existing functions and methods dynamically.
当内部函数获得和使用其外部函数的变量时,就称其为一个闭包。
When an inner function gains and USES access to its outer function's variables it is known as a closure.
这些由列表构建的简单指令构成了递归、高阶函数,甚至是闭包和continuation之类高级抽象的基础。
These simple list-building instructions form the foundation of recursions, higher-order functions, and even higher-order abstractions like closures and continuations.
闭包函数和lambda函数绝对不是新出现的概念;它们均来自函数编程领域。
The concepts of closures and lambda functions are definitely not new ones; they both come from the functional programming world.
一流的方法和函数(闭包)
闭包可以通过接口传递给静态方法和构造函数。
Closures can be passed as interface to static methods, constructors.
当你使用闭包时,记得包含函数的调用对象,包括所有的函数参数和本地变量,会有跟闭包一样的存活时期。
When you use a closure, remember that the call object of the enclosing function, including all function arguments and local variables, will last as long as the closure does.
当你使用闭包时,记得包含函数的调用对象,包括所有的函数参数和本地变量,会有跟闭包一样的存活时期。
When you use a closure, remember that the call object of the enclosing function, including all function arguments and local variables, will last as long as the closure does.
应用推荐