[OpenAjaxMobile] Dojo's (and Ext's and jQuery's) use of associative arrays as parameters
Adam Peller
apeller at us.ibm.com
Thu Jul 17 19:30:25 PDT 2008
Just a footnote to what Jon said about callbacks... dojo.xhr uses
dojo.Deferred, which is a more generalized mechanism for callbacks, copied
from Bob Ippolito's work on Mochi kit, which in turn was inspired by
Twisted (Python).
http://mochikit.com/doc/html/MochiKit/Async.html
I don't know how consistently the associative array approach is applied in
Dojo, but I think it's generally used for one or more of the following
reasons
1) the arguments are too numerous to list out, and it would be awkward to
make some optional while they are all ordered, so the hash is a natural
solution
2) to make "future-proof" without breaking the signature
3) to allow for reuse/mixins for functions with similar args
4) because the author was object-happy
-Adam
Jon
Ferraiolo/Menlo
Park/IBM at IBMUS To
Sent by: mobile at openajax.org
mobile-bounces at op cc
enajax.org
Subject
[OpenAjaxMobile] Dojo's (and Ext's
07/17/08 09:04 PM and jQuery's) use of associative
arrays as parameters
Please respond to
OpenAjax Alliance
discussion list
on Mobile Ajax
I am researching the Dojo build system (which came up both in the Mobile TF
and IDE WG phone calls this week). In going through some of the Dojo
materials, I found the following example within their hello_world tutorial
at (http://dojotoolkit.org/book/dojo-book-0-9/hello-world-tutorial):
------
dojo.xhrGet({
url: 'HelloWorldResponseGET.php',
load: helloCallback,
error: helloError,
content: {name: dojo.byId('name').value }
});
------
Two things to observe: (a) the single-object associative-array approach,
(b) two callbacks (success and error).
There are other parameters to xhrGet, including timeout controls, as shown
at (http://api.dojotoolkit.org/jsdoc/dojo/HEAD/dojo.xhrGet). There are a
number of APIs in Dojo that use the single-object associative-array
approach.
I also skimmed through some of the APIs for another popular library, Ext
JS, and they also used the single-object associative-array approach in a
number of their APIs.
jQuery doesn't seem to use single-object associative-arrays as parameters
as often as Dojo and Ext JS, but it does appear in some of jQuery's APIs.
Here is what I conclude:
* JavaScript developers are able to deal with APIs that use associative
arrays to pass name-value pairs
* But none of the major toolkits goes overboard using this technique
Jon
_______________________________________________
mobile mailing list
mobile at openajax.org
http://openajax.org/mailman/listinfo/mobile
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://openajax.org/pipermail/mobile/attachments/20080717/5a5ac1ad/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: graycol.gif
Type: image/gif
Size: 105 bytes
Desc: not available
Url : http://openajax.org/pipermail/mobile/attachments/20080717/5a5ac1ad/attachment.gif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pic08739.gif
Type: image/gif
Size: 1255 bytes
Desc: not available
Url : http://openajax.org/pipermail/mobile/attachments/20080717/5a5ac1ad/attachment-0001.gif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ecblank.gif
Type: image/gif
Size: 45 bytes
Desc: not available
Url : http://openajax.org/pipermail/mobile/attachments/20080717/5a5ac1ad/attachment-0002.gif
More information about the mobile
mailing list