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

Bob Ippolito bob at redivi.com
Thu Jun 29 23:31:57 EDT 2006


It's not cheating, it's just broken. That only works for objects in  
the global scope, local scope doesn't carry through function calls  
and JavaScript doesn't have macros. Don't pass go, don't collect $200.

-bob

On Jun 29, 2006, at 8:10 PM, Jon Sykes wrote:

> We were just bouncing some ideas round here:
>
> 		var bar;
> 		foo = new Object;
> 		foo.bar = new Object;
> 		
> 		function isUndefined(varname){
> 			try{
> 				eval(varname);
> 				return(false);
> 			}catch(e){
> 				//alert(e.message);
> 				if(e.message.match('defined')){return true;}
> 			}
> 		}
> 		
> 	
> 		
> 		alert("bar is "+isUndefined('bar')+".");
> 		alert("foo is "+isUndefined('foo')+".");
> 		alert("foo.bar is "+isUndefined('foo.bar')+".");
> 		alert("foobar is "+isUndefined('foobar')+".");
>
>
> But it's cheating really to have to supply the potential object as  
> a string.
>
> Also assuming that matching "defined" in the error is enough is  
> probably problematic, it covers "undefined" and "not defined" but  
> isn't exactly rock solid.
>
> Anyway, that was fun, back to business.
>
> Jon Sykes
>
>
> On Jun 29, 2006, at 6:45 PM, Bob Ippolito wrote:
>
>> Well, it's not possible to write a function that tests whether a  
>> global is defined or not (unless you check them as properties of  
>> global object). That's what dj_undef does isn't it?
>
> _______________________________________________
> dojo-contributors mailing list
> dojo-contributors at dojotoolkit.org
> http://dojotoolkit.org/mailman/listinfo/dojo-contributors




More information about the dojo-contributors mailing list