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

Scott J. Miles sjmiles at turboajax.com
Thu Jun 29 13:26:42 EDT 2006

Afaik, generally the exception happens as soon as 'foo' is evaluated, which
occurs before any implementation of dojo.lang.isUndefined can execute.

The reference named 'foo' itself has no relevance to bar when invoking
bar(foo), only the *value* of foo has relevance. In particular,
dojo.lang.isUndefined(undefined) correctly returns true.

Using a global variable that may not exist (in any expression) requires
window.foo or even dj_global.foo, possibly <context>["foo"] to support older

If you really wanted to extend isUndefined to do safe global checking you
would need to allow calls like so:

isUndefined("foo"); // maps to isUndefined(window["foo"])
isUndefined("foo", obj); // maps to isUndefined(obj["foo"])

Scott J. Miles
TurboAjax Group

-----Original Message-----
From: dojo-contributors-bounces at dojotoolkit.org
[mailto:dojo-contributors-bounces at dojotoolkit.org] On Behalf Of Jon Sykes
Sent: Thursday, June 29, 2006 8:08 AM
To: dojo dev.
Subject: [dojo-contributors] Re: dojo.lang.isUndefined()

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


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.



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.


Should I log this on Trac somewhere?

I see that Alex has a trac at:


or should I add it to:


Jon Sykes

More information about the dojo-contributors mailing list