Login Register

Part 3: JavaScript Programming With Dojo and Dijit

In addition to being useful in itself, Dijit is a testament to Dojo's solidness and performance. The fact that you can build a really nice, extensible widget framework on top of it shows how cool Dojo is.

But that's only the beginning. Other Dojo-based mini-frameworks like dojo.data and dojox.offline allow you to build data sources and offline storage, respectively, in object oriented fashion. With a bit of JavaScript, you can use these services and many others bundled with Dojo for your own Web 2.0 applications:

  • Object Oriented Class Helpers - JavaScript uses prototype-based, not class-based, object orientation natively.  Dojo essentially builds a class system on top, adding great features like inheritance, encapsulation, mixin classes, and more.  This will make Java and C# programmers feel at home, and help build solid Enterprise-level applications.
  • Modules - As your client code grows, it's harder to keep all functions and global variables from using the same name and wrecking each other.  Dojo adds a module system on top of JavaScript as part of its class layer.  Modules are like packages in Java.
  • Dijit Methods - As we've seen, you can create Dijit components programmatically - perfect for when you need 1000 tree nodes, for example.  You can also build your own Dijit widget classes, and extend the ones already there.
  • Events - Dojo generalizes the event system already present in JavaScript.  You can connect events to code, and the resulting app works in Firefox, IE, and Safari without modification.  It also introduces "double-blind" publish/subscribe events - perfect for loosely-coupled code.
  • XHR (Ajax) - Dojo adds a nice wrapper around native XmlHttpRequest services.  Often you can boil an XHR message-pass with one function call.  The data is given to you in text, XML, or in a JavaScript object via JSON. 
  • Drag and Drop - Often the bane of DHTML applications, drag and drop services are essential for easy user interaction.  Dojo's DnD layer is fast, cross-platform, and very straightforward.
  • Dojo.data - The Data module is an abstraction layer that makes gathering data from outside sources consistent.  Reading from a database or web service uses the same base calls.  You can write pluggable data modules for your own sources.
  • Dojo.query - Finding and manipulating HTML fragments is difficult.  But Dojo.query makes it as easy as CSS.  You can write sophsticated selectors, then apply an operation to all of them in one step.
  • i18n - Short for "Internationalization" ("i", "n" and the 18 characters between them), Dojo i18n services help make all of your code globally accessible with understandable date, number and currency formats, and translated resource bundles.
  • Back button handling - dojo.back saves your application from nervous users trying to use the Back button. One-page apps can destroy data at one touch of the back button. dojo.back alters the behavior of Back to make it less likely.
  • And more, more more! - As your apps get sophsiticated, you can also write them compactly using Dojo's language extension features, HTML style functions, cookie functions, and much more!