Monday, November 10, 2008

Dojo Does Raise Exceptions

Dojo does raise exceptions in some cases. As I tried out some example codes from Dojo Quick Start Guide: Events, I got exceptions.

The following codes explains the case:

var mineObj = {
aMethod: function() {
console.log("Running mineObj method A");
bMethod: function() {
console.log("Running mineObj method B");
dojo.addOnLoad(function() {
// run bMethod() whenever aMthod gets run
dojo.connect(mineObj, "aMethod", mineObj, "bMethod");
//dojo.connect(mineObj, "aMethod", mineObj, "bMethod1"); // exception!
//dojo.connect(mineObj, "aMethod1", mineObj, "bMethod"); // OK
// start chain of events
//mineObj.aMethod1(); // JavaScript error!

The second connect(commented out) will throw an exception in FireBug:
uncaught exception: dojo.hitch: scope["bMethod1"] is null (scope="[object Object]")

The connect fails to invoke method bMethod1 as it is not defined. However, the third connect call is OK.

The last commented out code is a JavaScript error in FireBug:
mineObj.aMethod1 is not a function