Dojo toolkit wrapper

I’ve been finding lately that my simplest blog posts grow the longest tails. So here is one for all you dojo toolkit users or wannabe’s. I started seeing the following in dojo scripts that I hadn’t seen before, and couldn’t find any specific comments about it.

;(function(d,$){ /* your code here */})(dojo, dojo.query)

The leading semicolon is a fudge in case you’re using the build tools and glomming multiple files and the one ahead of yours forgot its trailing semicolon. An extra semicolon won’t hurt anything.
In my world (linux conf files), a leading semicolon often is a comment marker, so even though I know that is not the case in ECMAscript (AKA Javascript), it still caused me to do a double take.

The purpose of the anonymous function is to parameterize dojo and dojo.query so that you can use d to refer to dojo, and the JQuery/prototype style $ as shorthand for queries. That’s all there is to it. It also serves to point up a less used way to both define and call a function all in one bang.

2 comments to Dojo toolkit wrapper

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>