这种情况下返回的函数对象就是一个闭包,其中封装了一些日志代码和最初的函数调用所需要的数据。
In this case the returned function object is a closure which encapsulates some logging code and the data needed to call the original function.
默认情况下,它们是由值传递的,意味着如果要更新传递到闭包函数定义内的值,则不更新外部值。
By default, they are passed by value, meaning that if we would update the value passed within the closure function definition, it would not update the outside value.
真正重要的是一下部分,迭代器和闭包一两下就显示出了它们的威力。
The real knockout is the next part, where the one-two punches of iterators and closures shows their power.
但是,在需要把逻辑封装到自己的范围内的情况下,闭包会十分有用。
Closures, however, can be useful in any context where we need to encapsulate logic inside its own scope.
在这种情况下使用闭包与在类外部使用闭包实现的目的相同:包含在小范围内绑定的特定函数。
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.
回想一下,如果用户不指定一个像list或show这样的操作的话,index闭包就是通往控制器的入口点。
Recall that the index closure is the entry point into the controller if the user doesn't specify a custom action like list or show.
在结束之前,我们来看一下Groovy闭包的一个附加用途。
Before we wrap up, let's look at one additional use of Groovy closures.
在默认情况下,服务并不与UR l相关联,但是您可以轻易地在控制器中创建一个闭包,使这些服务可以通过Web找到。
Services aren't associated with an URL by default, but you can easily create a closure in a controller to make them Web addressable.
然后这些闭包只在上面讨论的这些情形下才显得有趣:当某个内嵌函数被暴露在它所被定义的作用域外时。
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.
在依概率收敛的意义下,该过程的闭包也是椭球等高过程。
Under the meaning of convergence in probability the closure of this process is also the process of ellipsoidal equal height.
在依概率收敛的意义下,该过程的闭包也是椭球等高过程。
Under the meaning of convergence in probability the closure of this process is also the process of ellipsoidal equal height.
应用推荐