<?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"
	>
<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></description>
	<pubDate>Mon, 08 Sep 2008 07:17:41 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
		<item>
		<title>By: Anonymous</title>
		<link>http://www.sitepoint.com/blogs/2004/05/26/xmlhttprequest-and-javascript-closures/#comment-154687</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Mon, 15 Jan 2007 19:09:01 +0000</pubDate>
		<guid isPermaLink="false">#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-34664</link>
		<dc:creator>Morris Johns</dc:creator>
		<pubDate>Sun, 02 Jul 2006 23:24:06 +0000</pubDate>
		<guid isPermaLink="false">#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-13450</link>
		<dc:creator>robin</dc:creator>
		<pubDate>Thu, 02 Feb 2006 09:13:57 +0000</pubDate>
		<guid isPermaLink="false">#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-397</link>
		<dc:creator>Widow Maker</dc:creator>
		<pubDate>Wed, 31 Dec 1969 19:00:00 +0000</pubDate>
		<guid isPermaLink="false">#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-398</link>
		<dc:creator>sobri</dc:creator>
		<pubDate>Wed, 31 Dec 1969 19:00:00 +0000</pubDate>
		<guid isPermaLink="false">#comment-398</guid>
		<description>&lt;p&gt;Just thought I'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'm not sure of its status in Opera, but I'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-399</link>
		<dc:creator>Carl Smotricz</dc:creator>
		<pubDate>Wed, 31 Dec 1969 19:00:00 +0000</pubDate>
		<guid isPermaLink="false">#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 "this" to a variable - not sure why can'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've been struggling with this for days! The answer is that "this" is the context of the function/object definition (i.e. HTTPClient) at the time the constructor runs (i.e. at "new" 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="http://www.mozilla.org/projects/venkman/"&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 "remembers" the context it was defined in, including all variables (except "this", of course!) So when your callback runs, the "self" it refers to is the very "self" that was pointed at "this" 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 - 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-400</link>
		<dc:creator>HarryF</dc:creator>
		<pubDate>Wed, 31 Dec 1969 19:00:00 +0000</pubDate>
		<guid isPermaLink="false">#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-401</link>
		<dc:creator>Bryon Bean</dc:creator>
		<pubDate>Wed, 31 Dec 1969 19:00:00 +0000</pubDate>
		<guid isPermaLink="false">#comment-401</guid>
		<description>&lt;p&gt;-- snip --&lt;br /&gt;
// Have to assign "this" to a variable - not sure why can'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 - 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>
	<item>
		<title>By: Eric C.</title>
		<link>http://www.sitepoint.com/blogs/2004/05/26/xmlhttprequest-and-javascript-closures/#comment-402</link>
		<dc:creator>Eric C.</dc:creator>
		<pubDate>Wed, 31 Dec 1969 19:00:00 +0000</pubDate>
		<guid isPermaLink="false">#comment-402</guid>
		<description>&lt;p&gt;Great page, but the popup really pisses me off.  Embracing Mozilla but then using javascript code to cirucumvent its pop-up blocking is a bit hypocritical.  For other readers that find this page I suggest adding *sitepoint.com/popup* to your adblock list.&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>Great page, but the popup really pisses me off.  Embracing Mozilla but then using javascript code to cirucumvent its pop-up blocking is a bit hypocritical.  For other readers that find this page I suggest adding *sitepoint.com/popup* to your adblock list.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Brad Fults</title>
		<link>http://www.sitepoint.com/blogs/2004/05/26/xmlhttprequest-and-javascript-closures/#comment-403</link>
		<dc:creator>Brad Fults</dc:creator>
		<pubDate>Wed, 31 Dec 1969 19:00:00 +0000</pubDate>
		<guid isPermaLink="false">#comment-403</guid>
		<description>&lt;p&gt;This example, although useful in many ways with regard to learning, is hardly plausible for use in real-world applications. The code is bloated and many unnecessary structures are created. For a barebones XMLHTTP library, I suggest XHConn: [ http://xkr.us/code/javascript/XHConn/ ].&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>This example, although useful in many ways with regard to learning, is hardly plausible for use in real-world applications. The code is bloated and many unnecessary structures are created. For a barebones XMLHTTP library, I suggest XHConn: [ <a href="http://xkr.us/code/javascript/XHConn/" rel="nofollow">http://xkr.us/code/javascript/XHConn/</a> ].</p>]]></content:encoded>
	</item>
</channel>
</rss>
