Prev | Current Page 286 | Next

Frank Zammetti

"Practical DWR 2 Projects"

This JavaScript contains essentially ???stub??? objects that you call on, and DWR behind
the scenes makes the remote call to the server-side object. This gives you the illusion of
directly calling remote objects. That??™s precisely what this line is doing. It??™s calling the
getInboxContents() method of the MailRetriever object, or more precisely, of a new
MailRetriever object because a new object is created as a result of each call, so there is not
just one object to call. The only parameter we pass in this case is the JavaScript callback function
that will handle the return from the method call. This parameter is always present in all
the DWR code in this project (and indeed in most of the DWR code throughout this book),
and it is always the last parameter.
When the call returns, the replyGetInboxContents() function is called. Notice the somewhat
unusual way the function is defined: it is assigned to a variable! This gives us an easy way
to refer to the function. You can in fact have the callback function inline in the method call,
that is, something along the lines of
MailRetriever.getInboxContents(function replyGetInboxContents(str){alert(str);});
CHAPTER 4 n INSTAMAIL: AN AJAX-BASED WEBMAIL CLIENT 152
Most people, myself included, believe that is just simply harder to read, and thus I try and
avoid that where possible.


Pages:
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298