<?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: Bug: Object Killing in IE7</title>
	<atom:link href="http://ajaxian.com/archives/bug-object-killing-in-ie7/feed" rel="self" type="application/rss+xml" />
	<link>http://ajaxian.com/archives/bug-object-killing-in-ie7</link>
	<description>Cleaning up the web with Ajax</description>
	<lastBuildDate>Thu, 17 May 2012 07:43:39 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: Dustin Diaz</title>
		<link>http://ajaxian.com/archives/bug-object-killing-in-ie7/comment-page-1#comment-259587</link>
		<dc:creator>Dustin Diaz</dc:creator>
		<pubDate>Fri, 30 Nov 2007 19:14:25 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/bug-object-killing-in-ie7#comment-259587</guid>
		<description>Who the hell is this sitesmart person that keeps posting soft spam in the comments?</description>
		<content:encoded><![CDATA[<p>Who the hell is this sitesmart person that keeps posting soft spam in the comments?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jordan</title>
		<link>http://ajaxian.com/archives/bug-object-killing-in-ie7/comment-page-1#comment-259571</link>
		<dc:creator>Jordan</dc:creator>
		<pubDate>Fri, 30 Nov 2007 15:52:44 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/bug-object-killing-in-ie7#comment-259571</guid>
		<description>... and the comment causes the remaining script blocks to be commented out and thus invalid.</description>
		<content:encoded><![CDATA[<p>&#8230; and the comment causes the remaining script blocks to be commented out and thus invalid.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jordan</title>
		<link>http://ajaxian.com/archives/bug-object-killing-in-ie7/comment-page-1#comment-259570</link>
		<dc:creator>Jordan</dc:creator>
		<pubDate>Fri, 30 Nov 2007 15:50:38 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/bug-object-killing-in-ie7#comment-259570</guid>
		<description>Just to add to the discussion, each script block must be parsed and executed separately, and they cannot all be parsed together and then executed together, because the execution of one script block may affect whether or not the next script block runs. For example, imagine a scenario where the first script block uses document.write() to write out a comment ( </description>
		<content:encoded><![CDATA[<p>Just to add to the discussion, each script block must be parsed and executed separately, and they cannot all be parsed together and then executed together, because the execution of one script block may affect whether or not the next script block runs. For example, imagine a scenario where the first script block uses document.write() to write out a comment ( </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin</title>
		<link>http://ajaxian.com/archives/bug-object-killing-in-ie7/comment-page-1#comment-259569</link>
		<dc:creator>Martin</dc:creator>
		<pubDate>Fri, 30 Nov 2007 15:41:24 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/bug-object-killing-in-ie7#comment-259569</guid>
		<description>var test = {}; probably works because the script engine now properly (internally) marks test as existent in the global scope, whereas this[â€˜testâ€˜] = {} also creates the variable in the global scope but does not mark it properly. Or something like that. It is the inner working of the script engine that contains the bug, not your code.</description>
		<content:encoded><![CDATA[<p>var test = {}; probably works because the script engine now properly (internally) marks test as existent in the global scope, whereas this[â€˜testâ€˜] = {} also creates the variable in the global scope but does not mark it properly. Or something like that. It is the inner working of the script engine that contains the bug, not your code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JP</title>
		<link>http://ajaxian.com/archives/bug-object-killing-in-ie7/comment-page-1#comment-259563</link>
		<dc:creator>JP</dc:creator>
		<pubDate>Fri, 30 Nov 2007 13:09:10 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/bug-object-killing-in-ie7#comment-259563</guid>
		<description>The situation came up because we&#039;re adding Dojo to a legacy system.

The legacy system had script blocks that did an object check before creating the object:

if(typeof objectName != undefined){
  objectName = {};
}

Throw in a Dojo provide before that and suddenly you&#039;ve got vanishing objects all through your system.

I&#039;m still confused why doing:

var test = {};

instead of 

this[&#039;test&#039;] = {};

Solves the problem.  That seems to fly in the face of the ascertain that what it&#039;s doing is correct.  That said the quoted stuff above is very interesting, and opens a whole new light on it.</description>
		<content:encoded><![CDATA[<p>The situation came up because we&#8217;re adding Dojo to a legacy system.</p>
<p>The legacy system had script blocks that did an object check before creating the object:</p>
<p>if(typeof objectName != undefined){<br />
  objectName = {};<br />
}</p>
<p>Throw in a Dojo provide before that and suddenly you&#8217;ve got vanishing objects all through your system.</p>
<p>I&#8217;m still confused why doing:</p>
<p>var test = {};</p>
<p>instead of </p>
<p>this['test'] = {};</p>
<p>Solves the problem.  That seems to fly in the face of the ascertain that what it&#8217;s doing is correct.  That said the quoted stuff above is very interesting, and opens a whole new light on it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rodrigo</title>
		<link>http://ajaxian.com/archives/bug-object-killing-in-ie7/comment-page-1#comment-259560</link>
		<dc:creator>Rodrigo</dc:creator>
		<pubDate>Fri, 30 Nov 2007 11:11:11 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/bug-object-killing-in-ie7#comment-259560</guid>
		<description>I saw some code ...(In visual Basic) with 
if 1==2..
so it wouldn&#039;t surprise me to see people write code like that..</description>
		<content:encoded><![CDATA[<p>I saw some code &#8230;(In visual Basic) with<br />
if 1==2..<br />
so it wouldn&#8217;t surprise me to see people write code like that..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: FredCK</title>
		<link>http://ajaxian.com/archives/bug-object-killing-in-ie7/comment-page-1#comment-259559</link>
		<dc:creator>FredCK</dc:creator>
		<pubDate>Fri, 30 Nov 2007 10:52:56 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/bug-object-killing-in-ie7#comment-259559</guid>
		<description>@Dustin: you are right... probably just bad code would face this problem. But you know... it&#039;s always nice to understand why things happen... you always learn something from it.

Maybe next time I&#039;ll spend my time with the Big Bang instead :) or even better... coding!</description>
		<content:encoded><![CDATA[<p>@Dustin: you are right&#8230; probably just bad code would face this problem. But you know&#8230; it&#8217;s always nice to understand why things happen&#8230; you always learn something from it.</p>
<p>Maybe next time I&#8217;ll spend my time with the Big Bang instead :) or even better&#8230; coding!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dustin Diaz</title>
		<link>http://ajaxian.com/archives/bug-object-killing-in-ie7/comment-page-1#comment-259558</link>
		<dc:creator>Dustin Diaz</dc:creator>
		<pubDate>Fri, 30 Nov 2007 10:42:24 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/bug-object-killing-in-ie7#comment-259558</guid>
		<description>I feel like this is something I should get why we&#039;d need to do this.... but I don&#039;t. I hold similar regards to comment #1
- &quot;... who in the hell would ever test for that?&quot;</description>
		<content:encoded><![CDATA[<p>I feel like this is something I should get why we&#8217;d need to do this&#8230;. but I don&#8217;t. I hold similar regards to comment #1<br />
- &#8220;&#8230; who in the hell would ever test for that?&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: FredCK</title>
		<link>http://ajaxian.com/archives/bug-object-killing-in-ie7/comment-page-1#comment-259557</link>
		<dc:creator>FredCK</dc:creator>
		<pubDate>Fri, 30 Nov 2007 09:58:13 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/bug-object-killing-in-ie7#comment-259557</guid>
		<description>@Martin: I think we found the buggy part of IE.

From EcmaScript specs 10.1.3 - Variable Instantiation:

&lt;blockquote&gt;
For each VariableDeclaration or VariableDeclarationNoIn in the code, create a property of the variable object whose name is the Identifier in the VariableDeclaration or VariableDeclarationNoIn, whose value is undefined and whose attributes are determined by the type of code. &lt;b&gt;If there is already a property of the variable object with the name of a declared variable, the value of the property and its attributes are not changed.&lt;/b&gt; Semantically, this step must follow the creation of the FormalParameterList and FunctionDeclaration properties. In particular, if a declared variable has the same name as a declared function or formal parameter, the variable declaration does not disturb the existing property.
&lt;/blockquote&gt;

Yes, you caught it!

@Trevis: I suppose you are running the code in a page in the browser. So yes, &quot;this == window == global scope&quot;, and this global scope is certainly shared by all scripts running in that window.</description>
		<content:encoded><![CDATA[<p>@Martin: I think we found the buggy part of IE.</p>
<p>From EcmaScript specs 10.1.3 &#8211; Variable Instantiation:</p>
<blockquote><p>
For each VariableDeclaration or VariableDeclarationNoIn in the code, create a property of the variable object whose name is the Identifier in the VariableDeclaration or VariableDeclarationNoIn, whose value is undefined and whose attributes are determined by the type of code. <b>If there is already a property of the variable object with the name of a declared variable, the value of the property and its attributes are not changed.</b> Semantically, this step must follow the creation of the FormalParameterList and FunctionDeclaration properties. In particular, if a declared variable has the same name as a declared function or formal parameter, the variable declaration does not disturb the existing property.
</p></blockquote>
<p>Yes, you caught it!</p>
<p>@Trevis: I suppose you are running the code in a page in the browser. So yes, &#8220;this == window == global scope&#8221;, and this global scope is certainly shared by all scripts running in that window.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Trevor</title>
		<link>http://ajaxian.com/archives/bug-object-killing-in-ie7/comment-page-1#comment-259556</link>
		<dc:creator>Trevor</dc:creator>
		<pubDate>Fri, 30 Nov 2007 09:34:15 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/bug-object-killing-in-ie7#comment-259556</guid>
		<description>FredCK:

If that&#039;s true, wouldn&#039;t that be a bug? As you said, &quot;this&quot; is &quot;window&quot;, the global scope. Is there a global scope for each script?</description>
		<content:encoded><![CDATA[<p>FredCK:</p>
<p>If that&#8217;s true, wouldn&#8217;t that be a bug? As you said, &#8220;this&#8221; is &#8220;window&#8221;, the global scope. Is there a global scope for each script?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin</title>
		<link>http://ajaxian.com/archives/bug-object-killing-in-ie7/comment-page-1#comment-259555</link>
		<dc:creator>Martin</dc:creator>
		<pubDate>Fri, 30 Nov 2007 09:32:51 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/bug-object-killing-in-ie7#comment-259555</guid>
		<description>FredCK, your quotes from the spec prove that the &quot;var&quot; statement in the second script block rightly defines the variable (in the global context) although it is never reached. That is alright.

Now, the code in both script blocks has the global object as its execution context, right? The first block is parsed and executed, then the second block is parsed and executed, right?

In the first block, &quot;test&quot; is created. Now the second block executes. The &quot;var&quot; declaration should not have any effect (that is: not create and declare test as undefined), as &quot;test&quot; is already created.</description>
		<content:encoded><![CDATA[<p>FredCK, your quotes from the spec prove that the &#8220;var&#8221; statement in the second script block rightly defines the variable (in the global context) although it is never reached. That is alright.</p>
<p>Now, the code in both script blocks has the global object as its execution context, right? The first block is parsed and executed, then the second block is parsed and executed, right?</p>
<p>In the first block, &#8220;test&#8221; is created. Now the second block executes. The &#8220;var&#8221; declaration should not have any effect (that is: not create and declare test as undefined), as &#8220;test&#8221; is already created.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Serg</title>
		<link>http://ajaxian.com/archives/bug-object-killing-in-ie7/comment-page-1#comment-259553</link>
		<dc:creator>Serg</dc:creator>
		<pubDate>Fri, 30 Nov 2007 08:59:45 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/bug-object-killing-in-ie7#comment-259553</guid>
		<description>Weee :) I think there is no hope to have appropriate browser from Microsoft.</description>
		<content:encoded><![CDATA[<p>Weee :) I think there is no hope to have appropriate browser from Microsoft.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: FredCK</title>
		<link>http://ajaxian.com/archives/bug-object-killing-in-ie7/comment-page-1#comment-259552</link>
		<dc:creator>FredCK</dc:creator>
		<pubDate>Fri, 30 Nov 2007 08:49:01 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/bug-object-killing-in-ie7#comment-259552</guid>
		<description>@Trevor: that&#039;s is not exactly true. It is also known that each  block is executed separately. The second  runs like a new scope execution, which inherits all properties defined in the global scope from the first  block.</description>
		<content:encoded><![CDATA[<p>@Trevor: that&#8217;s is not exactly true. It is also known that each  block is executed separately. The second  runs like a new scope execution, which inherits all properties defined in the global scope from the first  block.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Trevor</title>
		<link>http://ajaxian.com/archives/bug-object-killing-in-ie7/comment-page-1#comment-259551</link>
		<dc:creator>Trevor</dc:creator>
		<pubDate>Fri, 30 Nov 2007 08:39:51 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/bug-object-killing-in-ie7#comment-259551</guid>
		<description>By that logic, the first alert should also spit out undefined.</description>
		<content:encoded><![CDATA[<p>By that logic, the first alert should also spit out undefined.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: FredCK</title>
		<link>http://ajaxian.com/archives/bug-object-killing-in-ie7/comment-page-1#comment-259550</link>
		<dc:creator>FredCK</dc:creator>
		<pubDate>Fri, 30 Nov 2007 08:25:42 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/bug-object-killing-in-ie7#comment-259550</guid>
		<description>In JavaScript, we have two scopes: global and function. Let&#039;s take the EcmaScript specifications, which could demonstrate that your code is buggy instead.

From 12.2 - Variable statement:

&lt;blockquote&gt;
If the variable statement occurs inside a FunctionDeclaration, the variables are defined with function-local scope in that function, as described in s10.1.3. Otherwise, &lt;b&gt;they are defined with global scope (that is, they are created as members of the global object, as described in 10.1.3) using property attributes&lt;/b&gt;.
&lt;/blockquote&gt;

In your case, &quot;this&quot; is &quot;window&quot;, the global scope. So, &quot;var test&quot; is the same as window[&#039;test&#039;], or even this[&#039;test&#039;].

Then, from the specs again:

&lt;blockquote&gt;
Variables are created when the execution scope is entered.
&lt;/blockquote&gt;

Opps... it&#039;s saying that all variables defined in the scope are created at the start of the code execution, not at the declaration point.

Now, right after it:

&lt;blockquote&gt;
Variables are initialised to &lt;b&gt;undefined&lt;/b&gt; when created. A variable with an Initialiser is assigned the value of its AssignmentExpression when the VariableStatement is executed, not when the variable is created.
&lt;/blockquote&gt;

Well... it sounds like IE&#039;s behavior reflects the specs perfectly.

At first look, it stills sounds bizarre, but well... probably the bug is the script code instead.</description>
		<content:encoded><![CDATA[<p>In JavaScript, we have two scopes: global and function. Let&#8217;s take the EcmaScript specifications, which could demonstrate that your code is buggy instead.</p>
<p>From 12.2 &#8211; Variable statement:</p>
<blockquote><p>
If the variable statement occurs inside a FunctionDeclaration, the variables are defined with function-local scope in that function, as described in s10.1.3. Otherwise, <b>they are defined with global scope (that is, they are created as members of the global object, as described in 10.1.3) using property attributes</b>.
</p></blockquote>
<p>In your case, &#8220;this&#8221; is &#8220;window&#8221;, the global scope. So, &#8220;var test&#8221; is the same as window['test'], or even this['test'].</p>
<p>Then, from the specs again:</p>
<blockquote><p>
Variables are created when the execution scope is entered.
</p></blockquote>
<p>Opps&#8230; it&#8217;s saying that all variables defined in the scope are created at the start of the code execution, not at the declaration point.</p>
<p>Now, right after it:</p>
<blockquote><p>
Variables are initialised to <b>undefined</b> when created. A variable with an Initialiser is assigned the value of its AssignmentExpression when the VariableStatement is executed, not when the variable is created.
</p></blockquote>
<p>Well&#8230; it sounds like IE&#8217;s behavior reflects the specs perfectly.</p>
<p>At first look, it stills sounds bizarre, but well&#8230; probably the bug is the script code instead.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fabian Jakobs</title>
		<link>http://ajaxian.com/archives/bug-object-killing-in-ie7/comment-page-1#comment-259549</link>
		<dc:creator>Fabian Jakobs</dc:creator>
		<pubDate>Fri, 30 Nov 2007 08:12:42 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/bug-object-killing-in-ie7#comment-259549</guid>
		<description>The JavaScript engine does not evaluate the the code. It just treats all variables, which are declared using &quot;var&quot; as local variable in the function they have been declared in. This happens while parsing the function and is independent of the fact whether the code will actually be executed.

One exception are variables, which are declared in the global scope (outside of any function). They are always global even if they are declared using &quot;var&quot;.

The strange thing about the example above, as happygiraffe pointed out, is just that IE seems to treat each script tag as itâ€™s own function.</description>
		<content:encoded><![CDATA[<p>The JavaScript engine does not evaluate the the code. It just treats all variables, which are declared using &#8220;var&#8221; as local variable in the function they have been declared in. This happens while parsing the function and is independent of the fact whether the code will actually be executed.</p>
<p>One exception are variables, which are declared in the global scope (outside of any function). They are always global even if they are declared using &#8220;var&#8221;.</p>
<p>The strange thing about the example above, as happygiraffe pointed out, is just that IE seems to treat each script tag as itâ€™s own function.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Trevor</title>
		<link>http://ajaxian.com/archives/bug-object-killing-in-ie7/comment-page-1#comment-259548</link>
		<dc:creator>Trevor</dc:creator>
		<pubDate>Fri, 30 Nov 2007 07:58:27 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/bug-object-killing-in-ie7#comment-259548</guid>
		<description>&quot;So that var declaration takes effect at the start of the function that itâ€™s running in.&quot;

What? You mean the JS engine evaluates code within an if statement that evaluates false? And that&#039;s &quot;correct&quot; behavior? Scope doesn&#039;t enter into it, code that is in an if statement that evaluates false should never run.</description>
		<content:encoded><![CDATA[<p>&#8220;So that var declaration takes effect at the start of the function that itâ€™s running in.&#8221;</p>
<p>What? You mean the JS engine evaluates code within an if statement that evaluates false? And that&#8217;s &#8220;correct&#8221; behavior? Scope doesn&#8217;t enter into it, code that is in an if statement that evaluates false should never run.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: happygiraffe</title>
		<link>http://ajaxian.com/archives/bug-object-killing-in-ie7/comment-page-1#comment-259547</link>
		<dc:creator>happygiraffe</dc:creator>
		<pubDate>Fri, 30 Nov 2007 07:54:29 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/bug-object-killing-in-ie7#comment-259547</guid>
		<description>That comment about &quot;should have no effect&quot; isn&#039;t exactly true.  Remember that JavaScript doesn&#039;t have &lt;em&gt;block scope&lt;/em&gt;, it has &lt;em&gt;function scope&lt;/em&gt;.  So that var declaration takes effect at the start of the function that it&#039;s running in. This means that &quot;test&quot; is a variable with the value &lt;code&gt;undefined&lt;/code&gt; in that scope.  Now to me it looks like IE7 is treating each script tag as it&#039;s own function.  I have no idea how correct or incorrect this is.

It&#039;s also worth pointing out that &lt;a href=&quot;http://jslint.com/&quot; rel=&quot;nofollow&quot;&gt;jslint&lt;/a&gt; would have warned you about this behaviour.</description>
		<content:encoded><![CDATA[<p>That comment about &#8220;should have no effect&#8221; isn&#8217;t exactly true.  Remember that JavaScript doesn&#8217;t have <em>block scope</em>, it has <em>function scope</em>.  So that var declaration takes effect at the start of the function that it&#8217;s running in. This means that &#8220;test&#8221; is a variable with the value <code>undefined</code> in that scope.  Now to me it looks like IE7 is treating each script tag as it&#8217;s own function.  I have no idea how correct or incorrect this is.</p>
<p>It&#8217;s also worth pointing out that <a href="http://jslint.com/" rel="nofollow">jslint</a> would have warned you about this behaviour.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: AndyB</title>
		<link>http://ajaxian.com/archives/bug-object-killing-in-ie7/comment-page-1#comment-259546</link>
		<dc:creator>AndyB</dc:creator>
		<pubDate>Fri, 30 Nov 2007 07:50:22 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/bug-object-killing-in-ie7#comment-259546</guid>
		<description>The smart quotes are ruining the code.</description>
		<content:encoded><![CDATA[<p>The smart quotes are ruining the code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Trevor</title>
		<link>http://ajaxian.com/archives/bug-object-killing-in-ie7/comment-page-1#comment-259545</link>
		<dc:creator>Trevor</dc:creator>
		<pubDate>Fri, 30 Nov 2007 07:49:32 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/bug-object-killing-in-ie7#comment-259545</guid>
		<description>This... has to be the work of some asshole dev who got sick of hearing about how terrible IE is. And I&#039;m sure QA wouldn&#039;t catch it because who in the hell would ever test for that?</description>
		<content:encoded><![CDATA[<p>This&#8230; has to be the work of some asshole dev who got sick of hearing about how terrible IE is. And I&#8217;m sure QA wouldn&#8217;t catch it because who in the hell would ever test for that?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

