Here, when callRemoteClassRemoteMethod() is called, as the result of clicking
a button, the call is made to RemoteClass.remoteMethod(), passing callbackProxy as the
value of the callback member of the metadata object (note that assigning a function to a
variable works the same as passing a reference to the function itself??”it??™s just two ways of referencing
the same thing). The real callback function named realCallback() (as if you couldn??™t
guess) takes two parameters, the return value from the remote method invocation, and some
other parameter, some other extra information. The callbackProxy() function, however,
accepts the single parameter DWR sends it. So, DWR calls callbackProxy() when the response
returns, which then calls the realCallback(), passing it that return value plus the extra information.
The proxy function will have as part of its execution context that extra information, so
it??™ll be passed along exactly as expected.
CHAPTER 2 n GETTING TO KNOW DWR 87
A WORD ON CLOSURES
Closures are one of those concepts that confuse the heck out of most developers initially, until it finally just
suddenly clicks, and then they see how very useful they are.
A closure can be defined as an expression (typically a function) that can have free variables together
with an environment that binds those variables (that ???closes??? the expression).
Pages:
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187