可以看到这个方法——状态、转换和事件——与闭包和散列映射结合起来,可以形成一个良好的DSL。
You can see that the methods — state, transition, and event — combined with closures and hash maps, make a nice DSL.
方法或函数可通过传入参数与闭包通信。
A method or function can communicate with a closure by passing in arguments.
闭包以uri的形式被公开给最终用户;方法则无法从浏览器中进行访问。
Closures are exposed to the end user as a URI; methods are not accessible from the browser.
这些仅仅是众多使用闭包进行迭代的方法中的两种。
These are just two more of the many ways that you can use closures to iterate.
不再有丑陋的匿名内部类:只要通过这些便捷方法使用闭包就可以!
No more ugly anonymous inner classes: just use closures through those shortcut methods!
这个示例中所使用的生成递归闭包的方法有些冗长。
The way of making recursive closures used in this example is a bit tedious.
它在此上下文中用作宏,通过闭包调用函数方法将在定义它的上下文中执行函数调用。
It ACTS like a macro in this context, where calling the method of function via the closure makes the function call in the context of where it's defined.
要直接使用fork/join,您必须使用带有一个任务闭包的runForkJoin()方法或一个将AbstractForkJoinWorker分为子类的任务类。
To use fork/join directly, you must either use the runForkJoin() method with a task closure or a task class that subclasses AbstractForkJoinWorker.
Ruby让您也可以编写使用自己的闭包的方法。
Ruby also lets you write methods that use your own closures.
当然,亲自操作Groovy是了解闭包对于这门美好的令人激动的语言是一笔多么大的财富的最好方法。
Of course, playing with Groovy yourself is the best way to see what a powerful asset closures are to the niftiness of this exciting language.
因为它是一个Seq,它具有一个foreach方法,并将一个闭包作为参数。
Because it is a Seq, it has a foreach method that takes a closure as a parameter.
闭包可以通过接口传递给静态方法和构造函数。
Closures can be passed as interface to static methods, constructors.
event命令也是一个方法调用,使用 符号(定义事件名)和闭包(定义转换)作为参数。
The event command is also a method invocation, taking a symbol (which defines the event's name) and a closure, which defines the transitions.
您会回忆起这个系列以前的文章中,闭包一般用于在List和map集合上应用的迭代器方法上。
You'll recall from previous articles in this series that closures are commonly used with iterator methods applied to List and Map collections.
每个方法调用和可选的闭包参数定义一个bean,并设置bean属性。
Each method call and optional closure argument defines a bean and sets bean properties.
例如,迭代器方法collect把闭包应用到集合中的每个元素上,并返回一个带有新值的新集合。
The iterator method collect, for example, applies a closure to every element in a collection and returns a new collection with the new values.
注意方法的最后一个参数是个闭包,在这个地方Groovy允许把它从实际参数列表中删除,并把它直接放在结束括号后面。
Note that where the final parameter to a method is a closure, Groovy permits that you can remove it from the list of actual parameters and place it immediately after the closing parenthesis.
Ruby拥有这些使用闭包块的相同列表操作方法,我不清楚collect()、map()和inject()多久出现一次。
Ruby has these same list-manipulation methods that use closure blocks, and I was struck by how often collect(), map(), and inject() appear.
一流的方法和函数(闭包)
lambda函数的概念是闭包的基础,并且提供了一种比PHP中已有的create_function函数改进了很多的动态创建函数的方法。
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.
闭包捕获真正被调用的Web服务方法存根(称为obj的函数对象)以及流作为日志输出。
The closure captures the information about the actual Web service method stub to be invoked (the function object called obj) as well as the stream for the log output.
将清单9中所示的对象引用调用为变量将自动调用__invoke魔术方法,使类本身用作闭包。
Calling the object reference shown in Listing 9 as a variable automatically calls the __invoke magic method, making the class itself act as a closure.
由于方法闭包,ActionScript 3.0中的事件处理得以提供内建的事件委托,从而得到了简化。
Event handling is simplified in ActionScript 3.0 thanks to method closures, which provide built-in event delegation.
在gpars中,可以利用接受闭包的factory方法或通过为groovyx . gpars . actor . AbstractPooledActor划分子类来创建actors。
In gpars, actors can be created from a factory method that takes a closure or by subclassing groovyx.gpars.actor.AbstractPooledActor.
这充许SQLLinQ提供程序分析传递给Where()方法的闭包,并将它转换成 SQL。
This allows the SQL LinQ provider to analyze the closure passed to the Where() method and translate it into SQL.
auth和list之间微妙但重要的一点区别是list是一个闭包,而auth是一个私有方法(闭包在定义中使用等号;方法使用圆括号)。
A subtle but important difference between auth and list is that list is a closure, whereas auth is a private method. (Closures use an equals sign in the definition; methods use parentheses.)
名为ages的List被发送给collect()方法,使用单个闭包 {element->return element +1 }作为参数。
The List referenced as ages is sent the collect() method with the single closure { element -> return element + 1 } as a parameter.
该代码有两个方法,即xml和html,每个都使用闭包。
The code has two methods — XML and HTML — that each take closures. Each method can selectively call its closure based on the contents of the accept header, as in Listing 10.
jQuery 提供一种简便的方法来劫持表单的 submit 事件。再一次传递一个闭包来处理该事件。
这种方法的一个抽象是:使用闭包,不需要开发访问者类的层次结构。
One attraction of this approach is that with closures you do not need to develop the visitor class hierarchy.
应用推荐