<?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: XMLHttpRequest and Javascript Closures</title>
	<atom:link href="http://www.sitepoint.com/blogs/2004/05/26/xmlhttprequest-and-javascript-closures/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sitepoint.com/blogs/2004/05/26/xmlhttprequest-and-javascript-closures/</link>
	<description>News, opinion, and fresh thinking for web developers and designers. The official podcast of sitepoint.com.</description>
	<lastBuildDate>Sat, 07 Nov 2009 23:35:20 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: World Wide Weird</title>
		<link>http://www.sitepoint.com/blogs/2004/05/26/xmlhttprequest-and-javascript-closures/comment-page-1/#comment-913376</link>
		<dc:creator>World Wide Weird</dc:creator>
		<pubDate>Fri, 10 Apr 2009 13:17:19 +0000</pubDate>
		<guid isPermaLink="false">1902091963#comment-913376</guid>
		<description>Use the &lt;em&gt;with&lt;/em&gt; keyword with code blocks that reference the object instead of passing &lt;em&gt;this&lt;/em&gt; or &lt;em&gt;self&lt;/em&gt;. This even works when, for example, calling the object&#039;s methods from setTimeout. :D</description>
		<content:encoded><![CDATA[<p>Use the <em>with</em> keyword with code blocks that reference the object instead of passing <em>this</em> or <em>self</em>. This even works when, for example, calling the object&#8217;s methods from setTimeout. :D</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://www.sitepoint.com/blogs/2004/05/26/xmlhttprequest-and-javascript-closures/comment-page-1/#comment-873951</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Thu, 05 Feb 2009 10:25:33 +0000</pubDate>
		<guid isPermaLink="false">1902091963#comment-873951</guid>
		<description>&lt;blockquote&gt;&lt;code&gt;&lt;/code&gt;&lt;/blockquote&gt;</description>
		<content:encoded><![CDATA[<blockquote><code></code></blockquote>]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://www.sitepoint.com/blogs/2004/05/26/xmlhttprequest-and-javascript-closures/comment-page-1/#comment-154687</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Mon, 15 Jan 2007 19:09:01 +0000</pubDate>
		<guid isPermaLink="false">1902091963#comment-154687</guid>
		<description>&lt;strong&gt;The head of this is strong&lt;/strong&gt;
&lt;blockquote&gt;my problem is related to the following code&lt;/blockquote&gt;</description>
		<content:encoded><![CDATA[<p><strong>The head of this is strong</strong></p>
<blockquote><p>my problem is related to the following code</p></blockquote>]]></content:encoded>
	</item>
	<item>
		<title>By: Morris Johns</title>
		<link>http://www.sitepoint.com/blogs/2004/05/26/xmlhttprequest-and-javascript-closures/comment-page-1/#comment-34664</link>
		<dc:creator>Morris Johns</dc:creator>
		<pubDate>Sun, 02 Jul 2006 23:24:06 +0000</pubDate>
		<guid isPermaLink="false">1902091963#comment-34664</guid>
		<description>I wrote an article explaining closures if you are interested:
http://blog.morrisjohns.com/javascript_closures_for_dummies</description>
		<content:encoded><![CDATA[<p>I wrote an article explaining closures if you are interested:<br />
<a href="http://blog.morrisjohns.com/javascript_closures_for_dummies" rel="nofollow">http://blog.morrisjohns.com/javascript_closures_for_dummies</a></p>]]></content:encoded>
	</item>
	<item>
		<title>By: robin</title>
		<link>http://www.sitepoint.com/blogs/2004/05/26/xmlhttprequest-and-javascript-closures/comment-page-1/#comment-13450</link>
		<dc:creator>robin</dc:creator>
		<pubDate>Thu, 02 Feb 2006 09:13:57 +0000</pubDate>
		<guid isPermaLink="false">1902091963#comment-13450</guid>
		<description>Where the hell has this code gone??!?</description>
		<content:encoded><![CDATA[<p>Where the hell has this code gone??!?</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Widow Maker</title>
		<link>http://www.sitepoint.com/blogs/2004/05/26/xmlhttprequest-and-javascript-closures/comment-page-1/#comment-397</link>
		<dc:creator>Widow Maker</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">1902091963#comment-397</guid>
		<description>&lt;p&gt;Thanks :)&lt;/p&gt;

&lt;p&gt;You approached this subject a wee while back in the Advanced PHP Forums, and keeping the topic in focus is great :)&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>Thanks :)</p>
<p>You approached this subject a wee while back in the Advanced PHP Forums, and keeping the topic in focus is great :)</p>]]></content:encoded>
	</item>
	<item>
		<title>By: sobri</title>
		<link>http://www.sitepoint.com/blogs/2004/05/26/xmlhttprequest-and-javascript-closures/comment-page-1/#comment-398</link>
		<dc:creator>sobri</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">1902091963#comment-398</guid>
		<description>&lt;p&gt;Just thought I&#039;d mention that XMLHttpRequest is implemented in Safari also.&lt;/p&gt;

&lt;p&gt;http://developer.apple.com/internet/webcontent/xmlhttpreq.html&lt;/p&gt;

&lt;p&gt;I&#039;m not sure of its status in Opera, but I&#039;m hoping for the best :)&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>Just thought I&#8217;d mention that XMLHttpRequest is implemented in Safari also.</p>
<p><a href="http://developer.apple.com/internet/webcontent/xmlhttpreq.html" rel="nofollow">http://developer.apple.com/internet/webcontent/xmlhttpreq.html</a></p>
<p>I&#8217;m not sure of its status in Opera, but I&#8217;m hoping for the best :)</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Carl Smotricz</title>
		<link>http://www.sitepoint.com/blogs/2004/05/26/xmlhttprequest-and-javascript-closures/comment-page-1/#comment-399</link>
		<dc:creator>Carl Smotricz</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">1902091963#comment-399</guid>
		<description>&lt;p&gt;Thanks for an excellent and very useful writeup!&lt;br /&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;br /&gt;
// Have to assign &quot;this&quot; to a variable - not sure why can&#039;t use directly&lt;br /&gt;
var self = this;&lt;br /&gt;
&lt;/p&gt;&lt;/blockquote&gt;&lt;/p&gt;

&lt;p&gt;I&#039;ve been struggling with this for days! The answer is that &quot;this&quot; is the context of the function/object definition (i.e. HTTPClient) at the time the constructor runs (i.e. at &quot;new&quot; time) but &lt;i&gt;the context of the call&lt;/i&gt; when a callback occurs; i.e. when StateChangeCallBack() is called, this points inside some completely different object. &lt;a href=&quot;http://www.mozilla.org/projects/venkman/&quot;&gt;Venkman&lt;/a&gt; (many Kudos to the Moz team for Venkman!) shows this quite nicely as you stumble through errors and exceptions.&lt;/p&gt;

&lt;p&gt;This is where JavaScript closure comes in: A function &quot;remembers&quot; the context it was defined in, including all variables (except &quot;this&quot;, of course!) So when your callback runs, the &quot;self&quot; it refers to is the very &quot;self&quot; that was pointed at &quot;this&quot; at the time of creation of HTTPClient.&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>Thanks for an excellent and very useful writeup!</p>
<blockquote><p>
// Have to assign &#8220;this&#8221; to a variable &#8211; not sure why can&#8217;t use directly<br />
var self = this;
</p>
</blockquote>
<p>I&#8217;ve been struggling with this for days! The answer is that &#8220;this&#8221; is the context of the function/object definition (i.e. HTTPClient) at the time the constructor runs (i.e. at &#8220;new&#8221; time) but <i>the context of the call</i> when a callback occurs; i.e. when StateChangeCallBack() is called, this points inside some completely different object. <a href="http://www.mozilla.org/projects/venkman/">Venkman</a> (many Kudos to the Moz team for Venkman!) shows this quite nicely as you stumble through errors and exceptions.</p>
<p>This is where JavaScript closure comes in: A function &#8220;remembers&#8221; the context it was defined in, including all variables (except &#8220;this&#8221;, of course!) So when your callback runs, the &#8220;self&#8221; it refers to is the very &#8220;self&#8221; that was pointed at &#8220;this&#8221; at the time of creation of HTTPClient.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: HarryF</title>
		<link>http://www.sitepoint.com/blogs/2004/05/26/xmlhttprequest-and-javascript-closures/comment-page-1/#comment-400</link>
		<dc:creator>HarryF</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">1902091963#comment-400</guid>
		<description>&lt;p&gt;Nice explaination. Many thanks for clearing that one up (and note to self, I should start using Venkman regularily).&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>Nice explaination. Many thanks for clearing that one up (and note to self, I should start using Venkman regularily).</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Bryon Bean</title>
		<link>http://www.sitepoint.com/blogs/2004/05/26/xmlhttprequest-and-javascript-closures/comment-page-1/#comment-401</link>
		<dc:creator>Bryon Bean</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">1902091963#comment-401</guid>
		<description>&lt;p&gt;-- snip --&lt;br /&gt;
// Have to assign &quot;this&quot; to a variable - not sure why can&#039;t use directly&lt;br /&gt;
        var self = this;&lt;br /&gt;
-- snip --&lt;/p&gt;

&lt;p&gt;After reading you article I just happend to stumble on this information, thought you might enjoy...&lt;/p&gt;

&lt;p&gt;(From http://www.crockford.com/javascript/private.html):&lt;/p&gt;

&lt;p&gt;function Container(param) {&lt;br /&gt;
   &lt;br /&gt;
    function dec() {&lt;br /&gt;
        if (secret &gt; 0) {&lt;br /&gt;
            secret -= 1;&lt;br /&gt;
            return true;&lt;br /&gt;
        } else {&lt;br /&gt;
            return false;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
   &lt;br /&gt;
    this.member = param;&lt;br /&gt;
    var secret = 3;&lt;br /&gt;
    var self = this;&lt;br /&gt;
}&lt;/p&gt;

&lt;p&gt;... &lt;/p&gt;

&lt;p&gt;By convention, we make a private self parameter. This is used to make the object available to the private methods. This is a workaround for an error in the ECMAScript Language Specification which causes this to be set incorrectly for inner functions.&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>&#8211; snip &#8211;<br />
// Have to assign &#8220;this&#8221; to a variable &#8211; not sure why can&#8217;t use directly<br />
        var self = this;<br />
&#8211; snip &#8211;</p>
<p>After reading you article I just happend to stumble on this information, thought you might enjoy&#8230;</p>
<p>(From <a href="http://www.crockford.com/javascript/private.html)" rel="nofollow">http://www.crockford.com/javascript/private.html)</a>:</p>
<p>function Container(param) {</p>
<p>    function dec() {<br />
        if (secret > 0) {<br />
            secret -= 1;<br />
            return true;<br />
        } else {<br />
            return false;<br />
        }<br />
    }</p>
<p>    this.member = param;<br />
    var secret = 3;<br />
    var self = this;<br />
}</p>
<p>&#8230; </p>
<p>By convention, we make a private self parameter. This is used to make the object available to the private methods. This is a workaround for an error in the ECMAScript Language Specification which causes this to be set incorrectly for inner functions.</p>]]></content:encoded>
	</item>
</channel>
</rss>
