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

Jon Sykes jon.sykes at media-hive.com
Thu Jun 29 13:36:45 EDT 2006


On Jun 29, 2006, at 1:26 PM, Scott J. Miles wrote:

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

Not sure I understand, if you put:

if((wh == undefined)&&(typeof wh == "undefined"))alert("foo is  
undefined");

in to the firebug console and hit enter, if you don't have foo set,  
it will fire the alert.  Isn't that what isUndefined should do?

>
> 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.

Again, not sure I understand what you mean.

>
> 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
> IE.

How much older IE do we need to support?

>
> 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"])
>

Yup I can see that being an extension.  But you would think that if  
you know what the parent obj is of the thing you want to check you  
could just do:

isUndefined(obj.foo);




> Regards,
> Scott J. Miles
> TurboAjax Group
> http://www.turboajax.com
>
> -----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
>
> 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
>
>
> _______________________________________________
> dojo-contributors mailing list
> dojo-contributors at dojotoolkit.org
> http://dojotoolkit.org/mailman/listinfo/dojo-contributors
>




More information about the dojo-contributors mailing list