<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/1.5.1.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: More Closure Strangeness</title>
	<link>http://dave.sunwheeltech.com/wordpress/2006/04/30/more-closure-strangeness/</link>
	<description>Dave Crane's weblog</description>
	<pubDate>Fri, 10 Sep 2010 20:11:34 +0000</pubDate>
	<generator>http://wordpress.org/?v=1.5.1.2</generator>

	<item>
		<title>by: dave</title>
		<link>http://dave.sunwheeltech.com/wordpress/2006/04/30/more-closure-strangeness/#comment-16359</link>
		<pubDate>Fri, 23 Mar 2007 14:51:36 +0000</pubDate>
		<guid>http://dave.sunwheeltech.com/wordpress/2006/04/30/more-closure-strangeness/#comment-16359</guid>
					<description>Hi Michael,

Yes, the closure has a reference to the variable, not to the variable's value. Passing it as an arg into a function does create a new variable.

The point that I was trying to make was that it's necessary to understand these intricacies in order to use closures, which might not be a problem for the likes of you or I, but can seem seriously weird to a newbie/casual JS programmer coming from a language such as Java. 

A year on, my gut feeling about closures has probably shifted more towards the love than hate, as my own programming style has continued to evolve, but I still maintain that they're the biggest source of confusion in learning JS (and conversely, of 'getting' JS as a language once you've understood them).

Thanks for dropping by.

Dave</description>
		<content:encoded><![CDATA[	<p>Hi Michael,</p>
	<p>Yes, the closure has a reference to the variable, not to the variable&#8217;s value. Passing it as an arg into a function does create a new variable.</p>
	<p>The point that I was trying to make was that it&#8217;s necessary to understand these intricacies in order to use closures, which might not be a problem for the likes of you or I, but can seem seriously weird to a newbie/casual JS programmer coming from a language such as Java. </p>
	<p>A year on, my gut feeling about closures has probably shifted more towards the love than hate, as my own programming style has continued to evolve, but I still maintain that they&#8217;re the biggest source of confusion in learning JS (and conversely, of &#8216;getting&#8217; JS as a language once you&#8217;ve understood them).</p>
	<p>Thanks for dropping by.</p>
	<p>Dave
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Michael Peters</title>
		<link>http://dave.sunwheeltech.com/wordpress/2006/04/30/more-closure-strangeness/#comment-16330</link>
		<pubDate>Fri, 23 Mar 2007 13:31:29 +0000</pubDate>
		<guid>http://dave.sunwheeltech.com/wordpress/2006/04/30/more-closure-strangeness/#comment-16330</guid>
					<description>I think your source of confusion is that you think variables are &quot;passed&quot; to closures. They aren't. A function acting as a clousure is &quot;bound&quot; to those variables. Any (and I mean *any*) updates to that variable will be seen by the closure. In your solution you &quot;pass&quot; the variable to a different function which will create an entirely new variable which is a copy of the one you passed. This is why it behaves like you want because each time you return the anonymous fuction it's bound to a different variable.

This is the same with any language that supports closures. It's just how they work.</description>
		<content:encoded><![CDATA[	<p>I think your source of confusion is that you think variables are &#8220;passed&#8221; to closures. They aren&#8217;t. A function acting as a clousure is &#8220;bound&#8221; to those variables. Any (and I mean *any*) updates to that variable will be seen by the closure. In your solution you &#8220;pass&#8221; the variable to a different function which will create an entirely new variable which is a copy of the one you passed. This is why it behaves like you want because each time you return the anonymous fuction it&#8217;s bound to a different variable.</p>
	<p>This is the same with any language that supports closures. It&#8217;s just how they work.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: will</title>
		<link>http://dave.sunwheeltech.com/wordpress/2006/04/30/more-closure-strangeness/#comment-340</link>
		<pubDate>Mon, 01 May 2006 04:35:03 +0000</pubDate>
		<guid>http://dave.sunwheeltech.com/wordpress/2006/04/30/more-closure-strangeness/#comment-340</guid>
					<description>i was asking about this same thing in some forum a few weeks back, and couldn't find a satisfactory answer for fixing the same problem you mention here without resorting to setting a property in a dom node. seemed like there should be some way to do it without resorting to that. someone suggested using timeout(). ack. stumbled in here looking for the errata for your book, and found the answer to my question.  thanks!  'closures bind references, not values' was what i didn't get. you'd think they'd build in unary operator so you could force closures to evaluate a reference.</description>
		<content:encoded><![CDATA[	<p>i was asking about this same thing in some forum a few weeks back, and couldn&#8217;t find a satisfactory answer for fixing the same problem you mention here without resorting to setting a property in a dom node. seemed like there should be some way to do it without resorting to that. someone suggested using timeout(). ack. stumbled in here looking for the errata for your book, and found the answer to my question.  thanks!  &#8216;closures bind references, not values&#8217; was what i didn&#8217;t get. you&#8217;d think they&#8217;d build in unary operator so you could force closures to evaluate a reference.
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
