[dojo-contributors] dojo/on - needs context

Mike Wilcox mike at mikewilcox.net
Fri Mar 2 10:34:29 EST 2012


I think I've brought this up before - I know I have personally with a few Dojo people. The 1.7 version of dojo/on, and dojo.subscribe are both missing a context option. I've had it explained to me the rationale behind it and I understand "the intention of the dev". I also didn't respond here without serious consideration and gave the new signature a chance of many months of usage. I was further encouraged by the recent addition of Function.bind() by Mozilla which I find highly useful. But I don't believe the new way works. 

dojo.hitch nor Function.bind are finger friendly replacements for a simple comma+this. It's much easier to write, and we've been trained to expect it. I have accounts from a few local friends using Dojo 1.7 that they had to revert to 1.6 because they thought dojo.on and dojo.subscribe were broken. I too thought it was broken for months, and now my new app is mixed with 1.7 and 1.6 code (which Rawld helped me with and probably was wondering what the hell I was doing).

In a perfect world, "this" would be optional in JavaScript, and the scope chain, when exhausting the lookup for the variable would then search the context chain for the property.  But it doesn't do that, to which I argue is a broken aspect of JavaScript. Like so many other things a library does, Dojo should help smooth over these rough patches for the dev. Especially since Dojo encourages Object Oriented Programming it shouldn't neglect helping to bind objects.

  
Mike Wilcox
http://clubajax.org
mike at mikewilcox.net





More information about the dojo-contributors mailing list