<?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/"
xmlns:series="http://unfoldingneurons.com/"
> <channel><title>Comments on: Limiting Variable Scope Using&#160;(function(){})();</title> <atom:link href="http://davidwalsh.name/javascript-closures/feed" rel="self" type="application/rss+xml" /><link>http://davidwalsh.name/javascript-closures</link> <description>Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</description> <lastBuildDate>Thu, 09 Feb 2012 09:28:55 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3</generator> <item><title>By: antonio torres</title><link>http://davidwalsh.name/javascript-closures/comment-page-1#comment-14503</link> <dc:creator>antonio torres</dc:creator> <pubDate>Mon, 14 Dec 2009 19:18:44 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=4358#comment-14503</guid> <description>hi David!i hope you can help me.
is it possible to implement your &quot;load more posts&quot; widget (http://net.tutsplus.com/tutorials/javascript-ajax/create-a-twitter-like-load-more-widget/) on a blogger blog? i guess the problem is the php implementation..
i like very much the script but i supose is not possible to implement it on a blogger thing...any idea on that, David? maybe a go around trick...
thank you very much in advance
antónio torres
www.vaiumagasosa.com</description> <content:encoded><![CDATA[<p>hi David!</p><p>i hope you can help me.<br
/> is it possible to implement your &#8220;load more posts&#8221; widget (<a
href="http://net.tutsplus.com/tutorials/javascript-ajax/create-a-twitter-like-load-more-widget/" rel="nofollow">http://net.tutsplus.com/tutorials/javascript-ajax/create-a-twitter-like-load-more-widget/</a>) on a blogger blog? i guess the problem is the php implementation..<br
/> i like very much the script but i supose is not possible to implement it on a blogger thing&#8230;</p><p>any idea on that, David? maybe a go around trick&#8230;<br
/> thank you very much in advance<br
/> antónio torres<br
/> <a
href="http://www.vaiumagasosa.com" rel="nofollow">http://www.vaiumagasosa.com</a></p> ]]></content:encoded> </item> <item><title>By: Jeremy Martin</title><link>http://davidwalsh.name/javascript-closures/comment-page-1#comment-14499</link> <dc:creator>Jeremy Martin</dc:creator> <pubDate>Mon, 14 Dec 2009 16:47:48 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=4358#comment-14499</guid> <description>Good post. Function scoping is a great way to keep your code clean. I often use a model like this:(function() {
// all my private stuff (vars and funcs) go here
var foo = &#039;I am scoped, no one else sees me&#039;;var apiMethods = {
// publicly exposed methods here
// these methods still have access to privately scoped members
bar : function() { alert(foo); }
};// expose api methods
window.MyNameSpace = apiMethods;
})();// alerts value of foo
MyNameSpace.bar();</description> <content:encoded><![CDATA[<p>Good post. Function scoping is a great way to keep your code clean. I often use a model like this:</p><p>(function() {<br
/> // all my private stuff (vars and funcs) go here<br
/> var foo = &#8216;I am scoped, no one else sees me&#8217;;</p><p> var apiMethods = {<br
/> // publicly exposed methods here<br
/> // these methods still have access to privately scoped members<br
/> bar : function() { alert(foo); }<br
/> };</p><p> // expose api methods<br
/> window.MyNameSpace = apiMethods;<br
/> })();</p><p>// alerts value of foo<br
/> MyNameSpace.bar();</p> ]]></content:encoded> </item> <item><title>By: David Walsh</title><link>http://davidwalsh.name/javascript-closures/comment-page-1#comment-14496</link> <dc:creator>David Walsh</dc:creator> <pubDate>Mon, 14 Dec 2009 15:17:01 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=4358#comment-14496</guid> <description>Ugh, updated my post as the terminology was off.  This should make more sense and be more direct.</description> <content:encoded><![CDATA[<p>Ugh, updated my post as the terminology was off.  This should make more sense and be more direct.</p> ]]></content:encoded> </item> <item><title>By: TheBigBabou</title><link>http://davidwalsh.name/javascript-closures/comment-page-1#comment-14495</link> <dc:creator>TheBigBabou</dc:creator> <pubDate>Mon, 14 Dec 2009 15:09:52 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=4358#comment-14495</guid> <description>Sorry David, I don&#039;t want to be offensive, but your code examples are no closures. What you are showing and describing is limiting variables to function scope.A closure is a function or codepointer which accesses variables outside its scope. Like here:(function () {var out = 1;window.setTimeout(function () {
alert(out);
}, 100);})()The closure here would be the function, which is the first parameter to setTimeout. It doesn&#039;t declare a variable &quot;out&quot;, but is able to access &quot;out&quot; from its outer function scope. As long as a variable stores a reference to this function, &quot;out&quot; is not freed from memory as well.</description> <content:encoded><![CDATA[<p>Sorry David, I don&#8217;t want to be offensive, but your code examples are no closures. What you are showing and describing is limiting variables to function scope.</p><p>A closure is a function or codepointer which accesses variables outside its scope. Like here:</p><p>(function () {</p><p>var out = 1;</p><p>window.setTimeout(function () {<br
/> alert(out);<br
/> }, 100);</p><p>})()</p><p>The closure here would be the function, which is the first parameter to setTimeout. It doesn&#8217;t declare a variable &#8220;out&#8221;, but is able to access &#8220;out&#8221; from its outer function scope. As long as a variable stores a reference to this function, &#8220;out&#8221; is not freed from memory as well.</p> ]]></content:encoded> </item> <item><title>By: Will</title><link>http://davidwalsh.name/javascript-closures/comment-page-1#comment-14493</link> <dc:creator>Will</dc:creator> <pubDate>Mon, 14 Dec 2009 15:03:41 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=4358#comment-14493</guid> <description>Doesn&#039;t this sort of miss the point of closures? I always thought that &#039;closure&#039; meant it &#039;closed&#039; over variables available to it when being declared, so those variables were available even when they went out of scope. It&#039;s hard to explain, but this example might help:function makeClosure() {
var t = &quot;foo&quot;;
return function() {
alert(t + &quot;bar&quot;);
}
}So, you&#039;d call makeClosure, which would return a function. Whenever the returned function was called, the value of t (&quot;foo&quot;) would still be available to it (thus returning &quot;foobar&quot;) even though t&#039;s scope had expired when makeClosure ended.</description> <content:encoded><![CDATA[<p>Doesn&#8217;t this sort of miss the point of closures? I always thought that &#8216;closure&#8217; meant it &#8216;closed&#8217; over variables available to it when being declared, so those variables were available even when they went out of scope. It&#8217;s hard to explain, but this example might help:</p><p> function makeClosure() {<br
/> var t = &#8220;foo&#8221;;<br
/> return function() {<br
/> alert(t + &#8220;bar&#8221;);<br
/> }<br
/> }</p><p>So, you&#8217;d call makeClosure, which would return a function. Whenever the returned function was called, the value of t (&#8220;foo&#8221;) would still be available to it (thus returning &#8220;foobar&#8221;) even though t&#8217;s scope had expired when makeClosure ended.</p> ]]></content:encoded> </item> <item><title>By: David Walsh</title><link>http://davidwalsh.name/javascript-closures/comment-page-1#comment-14489</link> <dc:creator>David Walsh</dc:creator> <pubDate>Mon, 14 Dec 2009 14:31:55 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=4358#comment-14489</guid> <description>In this case you could define $$(&#039;a&#039;) globally but my example was more trying to display the two closures working separately.</description> <content:encoded><![CDATA[<p>In this case you could define $$(&#8216;a&#8217;) globally but my example was more trying to display the two closures working separately.</p> ]]></content:encoded> </item> <item><title>By: Richard</title><link>http://davidwalsh.name/javascript-closures/comment-page-1#comment-14488</link> <dc:creator>Richard</dc:creator> <pubDate>Mon, 14 Dec 2009 14:29:23 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=4358#comment-14488</guid> <description>Proper programming technique is to define variables before use, and to use as few (preferably no) global variables as possible. What you have done in the examples are a work-around.I love all your other articles though!</description> <content:encoded><![CDATA[<p>Proper programming technique is to define variables before use, and to use as few (preferably no) global variables as possible. What you have done in the examples are a work-around.</p><p>I love all your other articles though!</p> ]]></content:encoded> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced (User agent is rejected)
Database Caching 1/14 queries in 0.008 seconds using disk: basic
Object Caching 670/671 objects using disk: basic

Served from: davidwalsh.name @ 2012-02-09 04:42:28 -->
