<?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: Fixing eval() to use global scope in IE</title>
	<atom:link href="http://josephsmarr.com/2007/01/31/fixing-eval-to-use-global-scope-in-ie/feed/" rel="self" type="application/rss+xml" />
	<link>http://josephsmarr.com/2007/01/31/fixing-eval-to-use-global-scope-in-ie/</link>
	<description>Thoughts on web development, tech, and life.</description>
	<lastBuildDate>Wed, 08 Feb 2012 11:00:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Kiler</title>
		<link>http://josephsmarr.com/2007/01/31/fixing-eval-to-use-global-scope-in-ie/comment-page-1/#comment-51356</link>
		<dc:creator>Kiler</dc:creator>
		<pubDate>Mon, 09 May 2011 02:15:00 +0000</pubDate>
		<guid isPermaLink="false">http://josephsmarr.com/2007/01/31/fixing-eval-to-use-global-scope-in-ie/#comment-51356</guid>
		<description> Wow this is a great resource.. I’m enjoying it.. good article

</description>
		<content:encoded><![CDATA[<p>Wow this is a great resource.. I’m enjoying it.. good article</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Perfection kills &#187; Global eval. What are the options?</title>
		<link>http://josephsmarr.com/2007/01/31/fixing-eval-to-use-global-scope-in-ie/comment-page-1/#comment-51327</link>
		<dc:creator>Perfection kills &#187; Global eval. What are the options?</dc:creator>
		<pubDate>Wed, 15 Dec 2010 19:07:26 +0000</pubDate>
		<guid isPermaLink="false">http://josephsmarr.com/2007/01/31/fixing-eval-to-use-global-scope-in-ie/#comment-51327</guid>
		<description>[...] are more similarly non-optimal soutions online, where folks seem to be taking trial-and-error approach, not realizing why things work the way they [...]</description>
		<content:encoded><![CDATA[<p>[...] are more similarly non-optimal soutions online, where folks seem to be taking trial-and-error approach, not realizing why things work the way they [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: infous</title>
		<link>http://josephsmarr.com/2007/01/31/fixing-eval-to-use-global-scope-in-ie/comment-page-1/#comment-336</link>
		<dc:creator>infous</dc:creator>
		<pubDate>Thu, 22 May 2008 15:57:36 +0000</pubDate>
		<guid isPermaLink="false">http://josephsmarr.com/2007/01/31/fixing-eval-to-use-global-scope-in-ie/#comment-336</guid>
		<description>Why don&#039;t you use window.eval(code) instead of dj_global.eval(code)? thinks, it can be use even inside object&#039;s method, but if you use &quot;dj_global = this&quot;, &quot;this&quot; is a current object, not window.
BTW, thanks a lot! good article :)</description>
		<content:encoded><![CDATA[<p>Why don&#8217;t you use window.eval(code) instead of dj_global.eval(code)? thinks, it can be use even inside object&#8217;s method, but if you use &#8220;dj_global = this&#8221;, &#8220;this&#8221; is a current object, not window.<br />
BTW, thanks a lot! good article <img src='http://josephsmarr.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mano</title>
		<link>http://josephsmarr.com/2007/01/31/fixing-eval-to-use-global-scope-in-ie/comment-page-1/#comment-304</link>
		<dc:creator>mano</dc:creator>
		<pubDate>Thu, 01 May 2008 10:45:33 +0000</pubDate>
		<guid isPermaLink="false">http://josephsmarr.com/2007/01/31/fixing-eval-to-use-global-scope-in-ie/#comment-304</guid>
		<description>the loader is async...</description>
		<content:encoded><![CDATA[<p>the loader is async&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joseph Smarr &#187; Handling GeoCoding Errors From Yahoo Maps</title>
		<link>http://josephsmarr.com/2007/01/31/fixing-eval-to-use-global-scope-in-ie/comment-page-1/#comment-26</link>
		<dc:creator>Joseph Smarr &#187; Handling GeoCoding Errors From Yahoo Maps</dc:creator>
		<pubDate>Tue, 20 Mar 2007 15:54:38 +0000</pubDate>
		<guid isPermaLink="false">http://josephsmarr.com/2007/01/31/fixing-eval-to-use-global-scope-in-ie/#comment-26</guid>
		<description>[...] PS: Special thanks to Mark Jen for finding me a decent code-writing plug-in for Windows Live Writer! Boy did I struggle with getting WordPress not to mangle my code in the eval post! [...]</description>
		<content:encoded><![CDATA[<p>[...] PS: Special thanks to Mark Jen for finding me a decent code-writing plug-in for Windows Live Writer! Boy did I struggle with getting WordPress not to mangle my code in the eval post! [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Trevin</title>
		<link>http://josephsmarr.com/2007/01/31/fixing-eval-to-use-global-scope-in-ie/comment-page-1/#comment-13</link>
		<dc:creator>Trevin</dc:creator>
		<pubDate>Wed, 07 Feb 2007 09:42:35 +0000</pubDate>
		<guid isPermaLink="false">http://josephsmarr.com/2007/01/31/fixing-eval-to-use-global-scope-in-ie/#comment-13</guid>
		<description>Hey Joseph, long time no see. Good to see you&#039;re still up to your old tricks and hacking away at code :)  Saw some great coverage on the Plaxo widget so congrats!</description>
		<content:encoded><![CDATA[<p>Hey Joseph, long time no see. Good to see you&#8217;re still up to your old tricks and hacking away at code <img src='http://josephsmarr.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   Saw some great coverage on the Plaxo widget so congrats!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel</title>
		<link>http://josephsmarr.com/2007/01/31/fixing-eval-to-use-global-scope-in-ie/comment-page-1/#comment-12</link>
		<dc:creator>Daniel</dc:creator>
		<pubDate>Sun, 04 Feb 2007 16:36:58 +0000</pubDate>
		<guid isPermaLink="false">http://josephsmarr.com/2007/01/31/fixing-eval-to-use-global-scope-in-ie/#comment-12</guid>
		<description>Don&#039;t swear at IE too much. What you&#039;re doing isn&#039;t standard ECMAscript and is deprecated in Javascript.</description>
		<content:encoded><![CDATA[<p>Don&#8217;t swear at IE too much. What you&#8217;re doing isn&#8217;t standard ECMAscript and is deprecated in Javascript.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jsmarr</title>
		<link>http://josephsmarr.com/2007/01/31/fixing-eval-to-use-global-scope-in-ie/comment-page-1/#comment-11</link>
		<dc:creator>jsmarr</dc:creator>
		<pubDate>Fri, 02 Feb 2007 16:41:29 +0000</pubDate>
		<guid isPermaLink="false">http://josephsmarr.com/2007/01/31/fixing-eval-to-use-global-scope-in-ie/#comment-11</guid>
		<description>Dave-the issue is that I&#039;m building my HTML by building up a big string of HTML and then injecting it into the DOM using innerHTML, because that&#039;s much faster that building using DOM methods (appendChild, etc.). But one problem with using innerHTML is that if I have instantiated objects with methods I want to call when an event happens (e.g. when you click on a contact, I want to call something like this.getContactManager().setContactSelected(true)) you have to wire those calls up AFTER you inject the innerHTML (because you&#039;re just injecting HTML, so there&#039;s no scope or object reference available). 

We used to solve this problem by giving each node we wanted to attach an event handler to a unique className, and then after we called innerHTML we would use getElementsByClassName to find the newly created element in the DOM and hook up the event with JavaScript. That&#039;s an elegant solution, but it&#039;s too slow if you&#039;re doing it a lot. So we decided to use global functions (e.g. g_plx_setContactSelected(&#039;contact-id-here&#039;)) instead, since those could be written directly into the innerHTML and the global function could then find the instantiated object to call the method on when it was invoked. 

This was great until we realized that it wasn&#039;t working in IE, because the code where the global function was defined was being loaded on-demand, and since we weren&#039;t using the global-scope eval (execScript) trick I mention above, those functions weren&#039;t ending up defined as event handlers. The global-eval trick fixes the problem though, and I&#039;m now quite happy with our setup (load code on-demand, build the UI with innerHTML, no walking the DOM to hook up events, still get to use instantiated objects and their instance methods).

I hope that clears things up!
Thanks, js</description>
		<content:encoded><![CDATA[<p>Dave-the issue is that I&#8217;m building my HTML by building up a big string of HTML and then injecting it into the DOM using innerHTML, because that&#8217;s much faster that building using DOM methods (appendChild, etc.). But one problem with using innerHTML is that if I have instantiated objects with methods I want to call when an event happens (e.g. when you click on a contact, I want to call something like this.getContactManager().setContactSelected(true)) you have to wire those calls up AFTER you inject the innerHTML (because you&#8217;re just injecting HTML, so there&#8217;s no scope or object reference available). </p>
<p>We used to solve this problem by giving each node we wanted to attach an event handler to a unique className, and then after we called innerHTML we would use getElementsByClassName to find the newly created element in the DOM and hook up the event with JavaScript. That&#8217;s an elegant solution, but it&#8217;s too slow if you&#8217;re doing it a lot. So we decided to use global functions (e.g. g_plx_setContactSelected(&#8216;contact-id-here&#8217;)) instead, since those could be written directly into the innerHTML and the global function could then find the instantiated object to call the method on when it was invoked. </p>
<p>This was great until we realized that it wasn&#8217;t working in IE, because the code where the global function was defined was being loaded on-demand, and since we weren&#8217;t using the global-scope eval (execScript) trick I mention above, those functions weren&#8217;t ending up defined as event handlers. The global-eval trick fixes the problem though, and I&#8217;m now quite happy with our setup (load code on-demand, build the UI with innerHTML, no walking the DOM to hook up events, still get to use instantiated objects and their instance methods).</p>
<p>I hope that clears things up!<br />
Thanks, js</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dave t</title>
		<link>http://josephsmarr.com/2007/01/31/fixing-eval-to-use-global-scope-in-ie/comment-page-1/#comment-10</link>
		<dc:creator>dave t</dc:creator>
		<pubDate>Fri, 02 Feb 2007 06:30:36 +0000</pubDate>
		<guid isPermaLink="false">http://josephsmarr.com/2007/01/31/fixing-eval-to-use-global-scope-in-ie/#comment-10</guid>
		<description>Don&#039;t quite understand what you are dealing with innerHTML.  Are you dealing with the fact that  tags don&#039;t get evaluated when included as part of innerHTML?</description>
		<content:encoded><![CDATA[<p>Don&#8217;t quite understand what you are dealing with innerHTML.  Are you dealing with the fact that  tags don&#8217;t get evaluated when included as part of innerHTML?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

