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

Aaron Boodman zboogs at gmail.com
Thu Jun 29 15:15:41 EDT 2006


Also, in Firefox this will raise a warning in the JS console if strict
mode is enabled. I just stopped writing code like this and used the
typeof test directly each time. :-/

- a

On 6/29/06, Scott J. Miles <sjmiles at turboajax.com> wrote:
> 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.
>
>
> _______________________________________________
> dojo-contributors mailing list
> dojo-contributors at dojotoolkit.org
> http://dojotoolkit.org/mailman/listinfo/dojo-contributors
>



More information about the dojo-contributors mailing list