Oracle Magazine Special offer for AjaxImpact.com Visitors!! Subscribe to Oracle Magazine for Free!
AJAX IMPACT


ARTICLES
Creating Your Own $
05/01/2009, by Neil Roberts



The bling, one of the best global variables in JavaScript. A tool which has come to mean, as a function, a way to locate a node or set of nodes. And, as a namespace, a simple way to access often-used functionality. “This can’t be done with Dojo,” you insist. But you’re wrong, it’s really easy. The ideas behind this little symbol are quite simple and I’m going to show you how to create your own customized version of it.

I’m going to look to jQuery for inspiration. Its fanbase is huge, its fans declare its syntax beautiful and expressive, and its “plugin” syntax is easy to use.

Your first decision is how you want to start your $ off. dojo.query will give us our node-locating abilities. Do you want it to support jQuery’s plugin syntax? Do you want it to contain all of the functions and properties of the normal dojo object?

The second decision is a little trickier. If the dojo object is updated during the life of your page, do you want the changes from the dojo object to make it into your $. This would generally happen after a dojo.require statement (which imports new code). Something like a dojo.require("dojo.behavior"); call that adds the behavior field to the dojo object. Another situation, though less likely, is that one of the properties on the dojo object might change. The tradeoff depends on whether or not you plan on overriding any of the fields that exist in the dojo object. If updates to dojo go from dojo to $, it means updates to $ go from $ to dojo.

   Read More...

 Rate this Ajax Articles
Error connecting to mysql