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

Scott J. Miles sjmiles at turboajax.com
Thu Jun 29 15:00:25 EDT 2006


What you are testing works fine if you test foo directly, i.e. (typeof foo
== "undefined"). But it's not possible to build that test into a function.

As I mentioned earlier, you are confusing foo itself with it's value.

function bar(wh) { // wh always exists here, even if it's value ===
undefined };
bar(foo); // throws an exception if foo doesn't exist, before bar is even
considered

It works like this:
1. function(<expression>) is invoked
2. <expression> is evaluated to find a value to send to function

This is what I meant by 'foo' itself being irrelevant to the function. Only
the value of foo is relevant, and it's in trying to discover the value of
foo that the exceptions is raised.

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 11:39 AM
To: dojo dev.
Subject: Re: [dojo-contributors] Re: dojo.lang.isUndefined()

Yup, I pasted what the function does now.  Rather than what the function
should do:

if((typeof wh == "undefined")||(wh == undefined))alert("wh is undefined");

Is what you are saying that if I did:

if(!dojo.lang.isUndefined(foo)){

	foo(bar);

}else{

alert("OMG you tried to do something with foo and it doesn't exist);

}

would cause a JS error anyway?

or would the above work if isUnDefined actually did test for undefined
global objects with needing them to be tested as a property of an existing
object?


On Jun 29, 2006, at 2:30 PM, Scott J. Miles wrote:

>> 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? <<
>
> It looks like you didn't paste what you meant to paste: your example 
> doesn't reference 'foo' at all. Putting what you did paste into the 
> console, an exception is thrown because 'wh' cannot be evaluated as an 
> operand to '==', which is exactly my point.





More information about the dojo-contributors mailing list