<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: javascript isset()</title>
	<atom:link href="http://luci.criosweb.ro/blog/2007/07/24/javascript-isset/feed/" rel="self" type="application/rss+xml" />
	<link>http://luci.criosweb.ro/blog/2007/07/24/javascript-isset/</link>
	<description>Never discourage anyone who continually makes progress</description>
	<lastBuildDate>Mon, 05 Jul 2010 07:06:34 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Glen</title>
		<link>http://luci.criosweb.ro/blog/2007/07/24/javascript-isset/comment-page-1/#comment-11952</link>
		<dc:creator>Glen</dc:creator>
		<pubDate>Sat, 28 Jun 2008 18:56:56 +0000</pubDate>
		<guid isPermaLink="false">http://luci.criosweb.ro/blog/?p=52#comment-11952</guid>
		<description>Forgot to mention... if you are testing for the existence of a global variable like this:

// var global;    // note it is commented out
isset(global);

.. will result in a &#039;global is not defined&#039; JS exception thrown.  Instead, you need to remember to do either one of these:

isset(window.global);        // these are equivalent
isset(window[&#039;global&#039;]);     // these are equivalent

I don&#039;t think there is any way to code for this in the isset() routine, since the exception is thrown before isset() is called.  JS doesn&#039;t seem to mind passing an undefined reference, as long as the highest-level piece (i.e. &#039;window&#039; in this case) does exist.  BTW, this will work the same if trying to test for the existence of a local variable ... like

function func()
{
  isset(loc);         // will also throw an exception
}

since (i think) you can&#039;t specifically reference local variables without targeting globals (though you can specifically reference globals via window.variable_name).

This is pretty basic stuff.  Do we really have to go to these lengths?</description>
		<content:encoded><![CDATA[<p>Forgot to mention&#8230; if you are testing for the existence of a global variable like this:</p>
<p>// var global;    // note it is commented out<br />
isset(global);</p>
<p>.. will result in a &#8216;global is not defined&#8217; JS exception thrown.  Instead, you need to remember to do either one of these:</p>
<p>isset(window.global);        // these are equivalent<br />
isset(window['global']);     // these are equivalent</p>
<p>I don&#8217;t think there is any way to code for this in the isset() routine, since the exception is thrown before isset() is called.  JS doesn&#8217;t seem to mind passing an undefined reference, as long as the highest-level piece (i.e. &#8216;window&#8217; in this case) does exist.  BTW, this will work the same if trying to test for the existence of a local variable &#8230; like</p>
<p>function func()<br />
{<br />
  isset(loc);         // will also throw an exception<br />
}</p>
<p>since (i think) you can&#8217;t specifically reference local variables without targeting globals (though you can specifically reference globals via window.variable_name).</p>
<p>This is pretty basic stuff.  Do we really have to go to these lengths?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Glen</title>
		<link>http://luci.criosweb.ro/blog/2007/07/24/javascript-isset/comment-page-1/#comment-11933</link>
		<dc:creator>Glen</dc:creator>
		<pubDate>Sat, 28 Jun 2008 05:17:18 +0000</pubDate>
		<guid isPermaLink="false">http://luci.criosweb.ro/blog/?p=52#comment-11933</guid>
		<description>That doesn&#039;t work all the time.  Function prototypes mess things up, for instance:

var a = new Array();
isset(a[&#039;pop&#039;]);         // returns true - as a.pop() exists

your routine will work for these cases (there are many) with this change:

function isset(varname)
{
  var t=typeof(varname); 
  return(t != &#039;undefined&#039; &amp;&amp; t != &#039;function&#039;);
}</description>
		<content:encoded><![CDATA[<p>That doesn&#8217;t work all the time.  Function prototypes mess things up, for instance:</p>
<p>var a = new Array();<br />
isset(a['pop']);         // returns true &#8211; as a.pop() exists</p>
<p>your routine will work for these cases (there are many) with this change:</p>
<p>function isset(varname)<br />
{<br />
  var t=typeof(varname);<br />
  return(t != &#8216;undefined&#8217; &amp;&amp; t != &#8216;function&#8217;);<br />
}</p>
]]></content:encoded>
	</item>
</channel>
</rss>
