<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>wide thoughts &#187; javascript</title>
	<atom:link href="http://kozak.si/widethoughts/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://kozak.si/widethoughts</link>
	<description>a blog of one of those ... software developer creatures</description>
	<lastBuildDate>Sat, 31 Jul 2010 12:30:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>deleting window properties</title>
		<link>http://kozak.si/widethoughts/2009/11/08/deleting-window-and-document-properties/</link>
		<comments>http://kozak.si/widethoughts/2009/11/08/deleting-window-and-document-properties/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 14:58:48 +0000</pubDate>
		<dc:creator>Gašper</dc:creator>
				<category><![CDATA[Thoughts]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://kozak.si/widethoughts/?p=533</guid>
		<description><![CDATA[Seems like there&#8217;s really something special about window and document objects in IE. Just as with iterating over window properties, there seems to be some weirdness about deleting the properties in window DOM object.

In IE, deleting a custom window property doesn&#8217;t work. The following code is fully ECMAScript compliant.



window.p = &#39;VAL&#39;;


delete window.p;



But it throws an [...]]]></description>
			<content:encoded><![CDATA[<p>Seems like there&#8217;s really something special about window and document objects in IE. Just as with <a href="http://kozak.si/widethoughts/2009/09/06/iterating-over-properties-in-window-object/">iterating over window properties</a>, there seems to be some weirdness about deleting the properties in <em>window</em> DOM object.<br />
<span id="more-533"></span><br />
In IE, deleting a custom window property doesn&#8217;t work. The following code is fully ECMAScript compliant.</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">window.<span class="me1">p</span> = <span class="st0">&#39;VAL&#39;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">delete</span> window.<span class="me1">p</span>;</div>
</li>
</ol>
</div>
<p>But it throws an exception in IE: Object doesn&#8217;t support this action. The same action works on custom objects:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> o = <span class="br0">&#123;</span><span class="br0">&#125;</span>;</div>
</li>
<li class="li1">
<div class="de1">o.<span class="me1">p</span> = <span class="st0">&#39;VAL&#39;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">delete</span> o.<span class="me1">p</span>;</div>
</li>
</ol>
</div>
<p>Just like with iterating over properties, it seems as if IE treats <em>window</em> like a special object, and it&#8217;s custom properties as something out of reach for certain actions. So I&#8217;ve come up with a solution to delete properties that works on all tested browsers:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">try</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">delete</span> obj.<span class="me1">prop</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">catch</span> <span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; obj.<span class="me1">prop</span> = undefined;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>You can test this <a href="http://kozak.si/widethoughts/wp-content/uploads/2009/11/prop_del.html">here</a>. This issue is present even in IE8, which is supposed to be much better with standards, but this example clearly shows that some very basic behavior is still missing from their Javascript engine.</p>
]]></content:encoded>
			<wfw:commentRss>http://kozak.si/widethoughts/2009/11/08/deleting-window-and-document-properties/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Iterating over properties in window object</title>
		<link>http://kozak.si/widethoughts/2009/09/06/iterating-over-properties-in-window-object/</link>
		<comments>http://kozak.si/widethoughts/2009/09/06/iterating-over-properties-in-window-object/#comments</comments>
		<pubDate>Sun, 06 Sep 2009 12:20:03 +0000</pubDate>
		<dc:creator>Gašper</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[browsers]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[objects]]></category>
		<category><![CDATA[properties]]></category>

		<guid isPermaLink="false">http://kozak.si/widethoughts/?p=436</guid>
		<description><![CDATA[I've been playing around a bit with JavaScript, and found out an interesting thing concerning property iteration in the <em>window</em> object in IE. In some cases, properties that are set on the window object, don't show up in the iteration.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing around a bit with JavaScript, and found out an interesting thing concerning property iteration in the <em>window</em> object in IE. In some cases, properties that are set on the <em>window</em> object don&#8217;t show up in the iteration.<br />
<span id="more-436"></span><br />
As you probably know, setting a variable outside a function (in the so called global scope) actually writes to the window object.</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">window.<span class="me1">X</span> = <span class="nu0">123</span>;</div>
</li>
<li class="li1">
<div class="de1">window<span class="br0">&#91;</span><span class="st0">&#39;X&#39;</span><span class="br0">&#93;</span> = <span class="nu0">123</span>;</div>
</li>
<li class="li1">
<div class="de1">X = <span class="nu0">123</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> X = <span class="nu0">123</span>;</div>
</li>
</ol>
</div>
<p>All of these do exactly the same: set a property <em>X</em> on object <em>window</em>.</p>
<p>But, when it comes to iterating window properties in IE (surprise), there seems to be a difference between the first two assignments and the last two. The code for iterating is simple; it iterates through all of the window&#8217;s properties and alerts if <em>X</em> is found.</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> v <span class="kw1">in</span> window<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>v == <span class="st0">&#39;X&#39;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span>v + <span class="st0">&#39;=&#39;</span> + window<span class="br0">&#91;</span>v<span class="br0">&#93;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>With the first two assignments (the ones that write explicitly to <em>window</em>), the property shows up, but with the last two (where properties are implicitly assigned to <em>window</em>), it doesn&#8217;t. It works in Firefox, Opera, Chrome, Safari, but not in IE (not even in IE8). You can try it out <a href='http://kozak.si/widethoughts/wp-content/uploads/2009/09/obj_iter.html'>here</a>.</p>
<p>Why this is so, I can only guess. The property obviously exists, because <em>window['X']</em> and <em>window.X</em> always contain the correct value. One possibility is that iterating over object properties in IE doesn&#8217;t iterate over the properties that object actually <em>owns</em>, but rather over a separate collection of property names. This separate collection isn&#8217;t updated properly when variables are assigned to the <em>window</em> object implicitly. Another possibility is that such variables exist in a global closure, and as such aren&#8217;t true members of the <em>window</em> object. When you access <em>window.X</em> and if it doesn&#8217;t exist, it&#8217;s looked up in that closure.</p>
<p>Interesting if not life-changing stuff. Maybe I&#8217;ll do some more research on this.</p>
]]></content:encoded>
			<wfw:commentRss>http://kozak.si/widethoughts/2009/09/06/iterating-over-properties-in-window-object/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
