<?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: closures -oh yeah?</title>
	<atom:link href="http://www.pedant.dk/2009/07/16/closures-oh-yeah/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pedant.dk/2009/07/16/closures-oh-yeah/</link>
	<description>I hack on things that lets you find stuff.</description>
	<lastBuildDate>Wed, 22 Jun 2011 15:35:27 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Harm Wibier</title>
		<link>http://www.pedant.dk/2009/07/16/closures-oh-yeah/#comment-38</link>
		<dc:creator>Harm Wibier</dc:creator>
		<pubDate>Thu, 16 Jul 2009 12:49:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.pedant.dk/?p=514#comment-38</guid>
		<description>:D First will do 2 and the second will do 3... think this is a great example of why one shouldn&#039;t use closures to much ;)</description>
		<content:encoded><![CDATA[<p> <img src='http://www.pedant.dk/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  First will do 2 and the second will do 3&#8230; think this is a great example of why one shouldn&#039;t use closures to much <img src='http://www.pedant.dk/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Peat</title>
		<link>http://www.pedant.dk/2009/07/16/closures-oh-yeah/#comment-37</link>
		<dc:creator>Mike Peat</dc:creator>
		<pubDate>Thu, 16 Jul 2009 12:30:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.pedant.dk/?p=514#comment-37</guid>
		<description>Where did my indentation go dammit!  ;-)</description>
		<content:encoded><![CDATA[<p>Where did my indentation go dammit!  <img src='http://www.pedant.dk/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Peat</title>
		<link>http://www.pedant.dk/2009/07/16/closures-oh-yeah/#comment-36</link>
		<dc:creator>Mike Peat</dc:creator>
		<pubDate>Thu, 16 Jul 2009 12:28:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.pedant.dk/?p=514#comment-36</guid>
		<description>IMO, more fun is this, which demonstrates the closure even more clearly and uses a lambda as well::

 var a=1;
 var b = function() {
    var a;
    return function() {
        a=2;
        return a;
    };
 }();
 a=3;
 var c=b();
 alert(c);
 alert(a);</description>
		<content:encoded><![CDATA[<p>IMO, more fun is this, which demonstrates the closure even more clearly and uses a lambda as well::</p>
<p> var a=1;<br />
 var b = function() {<br />
    var a;<br />
    return function() {<br />
        a=2;<br />
        return a;<br />
    };<br />
 }();<br />
 a=3;<br />
 var c=b();<br />
 alert(c);<br />
 alert(a);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jakob Kruse</title>
		<link>http://www.pedant.dk/2009/07/16/closures-oh-yeah/#comment-35</link>
		<dc:creator>Jakob Kruse</dc:creator>
		<pubDate>Thu, 16 Jul 2009 11:53:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.pedant.dk/?p=514#comment-35</guid>
		<description>Var det et oprigtigt sp&#248;rgsm&#229;l?

Der erkl&#230;res to variabler ved navn &#039;a&#039;, &#233;n i global kontekst og &#233;n i kontekst af funktionen &#039;foo&#039;. Den globale &#039;a&#039; initieres til v&#230;rdien 1, men rettes umiddelbart efter erkl&#230;ringen af &#039;foo&#039; til 3. S&#229; kaldes &#039;foo&#039;, som returnerer en funktion der piller ved v&#230;rdien af den lokale a og i &#248;vrigt returnerer 2. Denne returnerer funktion kaldes, og returv&#230;rdien (alts&#229; 2) gemmes i &#039;c&#039;. Til sidste udskrives &#039;c&#039; (2) og &#039;a&#039; (3).

Et forholdsvis trivielt eksempel p&#229; closures i &#248;vrigt, der kun spiller ind her ved at det &#039;a&#039; der refereres til fra &#039;bar&#039; funktionen, altid er den der er erkl&#230;ret i &#039;foo&#039;.</description>
		<content:encoded><![CDATA[<p>Var det et oprigtigt sp&oslash;rgsm&aring;l?</p>
<p>Der erkl&aelig;res to variabler ved navn &#039;a&#039;, &eacute;n i global kontekst og &eacute;n i kontekst af funktionen &#039;foo&#039;. Den globale &#039;a&#039; initieres til v&aelig;rdien 1, men rettes umiddelbart efter erkl&aelig;ringen af &#039;foo&#039; til 3. S&aring; kaldes &#039;foo&#039;, som returnerer en funktion der piller ved v&aelig;rdien af den lokale a og i &oslash;vrigt returnerer 2. Denne returnerer funktion kaldes, og returv&aelig;rdien (alts&aring; 2) gemmes i &#039;c&#039;. Til sidste udskrives &#039;c&#039; (2) og &#039;a&#039; (3).</p>
<p>Et forholdsvis trivielt eksempel p&aring; closures i &oslash;vrigt, der kun spiller ind her ved at det &#039;a&#039; der refereres til fra &#039;bar&#039; funktionen, altid er den der er erkl&aelig;ret i &#039;foo&#039;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Peat</title>
		<link>http://www.pedant.dk/2009/07/16/closures-oh-yeah/#comment-34</link>
		<dc:creator>Mike Peat</dc:creator>
		<pubDate>Thu, 16 Jul 2009 11:23:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.pedant.dk/?p=514#comment-34</guid>
		<description>The second alert will return whatever &quot;a&quot; has been set to most recently... but which &quot;a&quot;?  The global one declared at the top, because the other one is local to the function foo and only exists while that is executing.  So the line &quot;a=3;&quot; is that most recent assignment, so the second Alert pops-up &quot;3&quot;.

The first alert is more complicated.  It shows the value of &quot;c&quot;.  &quot;c&quot; is assigned to the returned value from &quot;b()&quot; and b has been assigned to &quot;foo()&quot;.  foo() in turn returns the *function* &quot;bar&quot;, so &quot;b&quot; is &quot;bar&quot;, so &quot;b()&quot; is &quot;bar()&quot; (NOT foo(), BTW.)  &quot;bar()&quot; assigns 2 to the local variable &quot;a&quot; of foo and then returns it (it could be anything - it is what it returns that counts, that it is a is a distraction!), so &quot;c&quot; contains (has the value of) the return from &quot;bar()&quot;, so the first Alert (&quot;Alert(c)&quot;) pops-up &quot;2&quot;.

Mike</description>
		<content:encoded><![CDATA[<p>The second alert will return whatever &quot;a&quot; has been set to most recently&#8230; but which &quot;a&quot;?  The global one declared at the top, because the other one is local to the function foo and only exists while that is executing.  So the line &quot;a=3;&quot; is that most recent assignment, so the second Alert pops-up &quot;3&quot;.</p>
<p>The first alert is more complicated.  It shows the value of &quot;c&quot;.  &quot;c&quot; is assigned to the returned value from &quot;b()&quot; and b has been assigned to &quot;foo()&quot;.  foo() in turn returns the *function* &quot;bar&quot;, so &quot;b&quot; is &quot;bar&quot;, so &quot;b()&quot; is &quot;bar()&quot; (NOT foo(), BTW.)  &quot;bar()&quot; assigns 2 to the local variable &quot;a&quot; of foo and then returns it (it could be anything &#8211; it is what it returns that counts, that it is a is a distraction!), so &quot;c&quot; contains (has the value of) the return from &quot;bar()&quot;, so the first Alert (&quot;Alert(c)&quot;) pops-up &quot;2&quot;.</p>
<p>Mike</p>
]]></content:encoded>
	</item>
</channel>
</rss>

