Dojo Fundamentals: Creating Object-Oriented Widgets

by Matthew Russell

After a batch of feedback about the way that our previous Short Cut on Dojo was titled and marketed, we decided to update it for version 1.0 (the previous version targeted 0.9), make the title more descriptive of the Short Cut's focus on creating custom widgets, and try it all again.

Here's the link to the updated Short Cut.

One caveat is that the URLs for the code examples in it point to version 1.0.0 of the code on AOL's Content Delivery Network. The latest Dojo build features the 1.0.2 code (a significant bug fix release). While the example code should work the same way either way, you'll want to use the 1.0.2 code in any actual development you do over the CDN.

For those who haven't heard of Dojo, it's a fantastic JavaScript toolkit that you really don't want to live without if you are a web developer in this day and age. In addition to providing facilities that comprise a JavaScript standard library, you also get a library of amazing out-of-the-box widgets and build tools. You can read a short ONLamp article about it here if you're looking for a drive-by overview.

Also, stay turned for the upcoming book that'll be available early next year.

PS - What more could someone possibly ask for on Christmas morning than a Short Cut on Dojo? It makes a great stocking stuffer :)


Richard Bondi
2008-02-09 15:36:44
Dear Matthew,

Thank you for you great Short Cut. Is there some place we can ask questions that you might answer in the forthcoming book? For example, why does Dojo have its own eval()? The 1.0.2 code comment doesn't explain anything, it is just cryptic:

dojo["eval"] = function(/*String*/ scriptFragment) {
// summary:
// Perform an evaluation in the global scope.
// Use this rather than
// calling 'eval()' directly.
// description:
// Placed in a separate function to minimize
// size of trapped
// evaluation context.

Huh? "trapped context"?? Wha-?


2008-02-09 17:07:50
Richard, thanks for the kind words. If you enjoyed the ShortCut please do take a moment to write a good review over at the same place you bought it ;)

As far as the dojo.eval function goes, I agree that the comment isn't very intuitive, and as I understand it, the actual issue is a arcane one involving some subtleties about how IE performs eval with regard to dynamically loaded content (if you don't know how closures work in JavaScript that would be an excellent topic to research right away.)

One thing I can tell you about Dojo is that there is a lot of machinery under the hood and, fortunately, to write a good app with Dojo, you generally don't even need to worry about things like dojo.eval which is defined in the loader (the stuff that bootstraps Dojo.) Most of the toolkit is automation, but there are a few fairly obscure fixes Dojo provides here and there and it looks like you may have just stumbled across one of them. (The trac ticket that referenced some eval issues was quite involved and there was a lot of discussion.)

As far as a forum to ask questions, do know that you can go to #dojo on to ask general dojo questions, but if you want to suggest specifics that you think are important for the book (which you can pre-order on Amazon , although it'll appear in the O'Reilly catalog soon enough if you want to wait for it), feel free to chat right here.

I plan to do a little blogging here on ONLamp once the book appears in the O'Reilly catalog (hopefully next week), and hopefully, a lot of good suggestions will come up there too.

2008-03-19 02:11:17
i like your artical