[dojo-contributors] Re: dojo.lang.isUndefined()

Jon Sykes jon.sykes at media-hive.com
Thu Jun 29 11:07:40 EDT 2006


Is there a reason that isUndefined is structured the way it is, such  
that an undefined variable/object will throw an error.

dojo.lang.isUndefined = function(wh){
	return ((wh == undefined)&&(typeof wh == "undefined"));
}

if you do

dojo.lang.isUndefined(foo);

with no other reference to foo in your code it'll throw a JS error,  
becuase JS doesn't like checking for objects that don't exist, rather  
preferring you to checkf ro properties of existing objects.


so...

dojo.lang.isUndefined(window.foo);

will return False as expected.

I was just talking with Mr. Wiltshire about this, and one idea I had  
was that if you did:

dojo.lang.isUndefined = function(wh){
	return ((typeof wh == "undefined")||(wh == undefined));
}

That way actual real undefined objects will not fail, but will return  
false as expected.  My logic being that I assume we're testing for  
two possible states, if the first in the above two is true it won't  
even try to do the second one (which throws the error) because we're  
using an OR, but if it doesn't it'll just check the second possible  
undefined to cover bases.

Thoughts?

Should I log this on Trac somewhere?

I see that Alex has a trac at:

http://trac.dojotoolkit.org/changeset/1418

or should I add it to:

http://trac.dojotoolkit.org/changeset/2118



Jon Sykes







More information about the dojo-contributors mailing list