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

Jon Sykes jon.sykes at media-hive.com
Thu Jun 29 23:10:12 EDT 2006


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?




More information about the dojo-contributors mailing list