<?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 for Skilldrick</title>
	<atom:link href="http://skilldrick.co.uk/comments/feed/" rel="self" type="application/rss+xml" />
	<link>http://skilldrick.co.uk</link>
	<description>A blog about programming and related stuff by Nick Morgan</description>
	<lastBuildDate>Sun, 05 Feb 2012 03:36:27 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>Comment on Closures explained with JavaScript by 深入理解JavaScript系列（4）：立即调用的函数表达式 &#124; Flash开发者大会</title>
		<link>http://skilldrick.co.uk/2011/04/closures-explained-with-javascript/comment-page-1/#comment-8979</link>
		<dc:creator>深入理解JavaScript系列（4）：立即调用的函数表达式 &#124; Flash开发者大会</dc:creator>
		<pubDate>Sun, 05 Feb 2012 03:36:27 +0000</pubDate>
		<guid isPermaLink="false">http://skilldrick.co.uk/?p=1002#comment-8979</guid>
		<description>&lt;p&gt;[...] Closures explained with JavaScript - Nick Morgan    此条目由 大脸猫catfly 发表在 Javascript 分类目录，并贴了 深入理解JavaScript系列 标签。将固定链接加入收藏夹。 [...]&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>[...] Closures explained with JavaScript - Nick Morgan    此条目由 大脸猫catfly 发表在 Javascript 分类目录，并贴了 深入理解JavaScript系列 标签。将固定链接加入收藏夹。 [...]</p>]]></content:encoded>
	</item>
	<item>
		<title>Comment on The end of progressive enhancement revisited by Drogon</title>
		<link>http://skilldrick.co.uk/2011/05/the-end-of-progressive-enhancement-revisited/comment-page-1/#comment-7887</link>
		<dc:creator>Drogon</dc:creator>
		<pubDate>Tue, 10 Jan 2012 17:57:51 +0000</pubDate>
		<guid isPermaLink="false">http://skilldrick.co.uk/?p=1086#comment-7887</guid>
		<description>&lt;p&gt;Another thing to consider is the cost (in time, resources, etc) of making progressive enhancements versus the benefit gained. PE seems to really slow down development of the front end since in many cases you are doing extra work to get things working both server and client side --even if server side code is re-used as much as possible. Also, PE tends not to work well with advanced client technologies and frameworks like json and knockout/backbone. Whether or not I&#039;m working on document-based or app-based web project --in many cases I couldn&#039;t really say which, seems like the lines blur a lot-- here is my (new) decision tree;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;If SEO is a concern, use progressive enhancement. Don&#039;t rely on rumors that content 
loaded from javascript gets indexed!&lt;/li&gt;
&lt;li&gt;If Accessiblity is a concern, use progressive enhancement. Just not ready for js in this 
arena.&lt;/li&gt;
&lt;li&gt;If lack of javascript is a major concern, use progressive enhancement. Not sure if this 
should ever be a major concern anymore...&lt;/li&gt;
&lt;li&gt;If it&#039;s simple content where js will buy you little, just do the traditional web development&lt;/li&gt;
&lt;li&gt;Otherwise, rely on clean javascript and server-side services, take and OO approach 
using a js framework and use jquery!&lt;/li&gt;
&lt;/ol&gt;
</description>
		<content:encoded><![CDATA[<p>Another thing to consider is the cost (in time, resources, etc) of making progressive enhancements versus the benefit gained. PE seems to really slow down development of the front end since in many cases you are doing extra work to get things working both server and client side &#8211;even if server side code is re-used as much as possible. Also, PE tends not to work well with advanced client technologies and frameworks like json and knockout/backbone. Whether or not I&#8217;m working on document-based or app-based web project &#8211;in many cases I couldn&#8217;t really say which, seems like the lines blur a lot&#8211; here is my (new) decision tree;</p>

<ol>
<li>If SEO is a concern, use progressive enhancement. Don&#8217;t rely on rumors that content 
loaded from javascript gets indexed!</li>
<li>If Accessiblity is a concern, use progressive enhancement. Just not ready for js in this 
arena.</li>
<li>If lack of javascript is a major concern, use progressive enhancement. Not sure if this 
should ever be a major concern anymore&#8230;</li>
<li>If it&#8217;s simple content where js will buy you little, just do the traditional web development</li>
<li>Otherwise, rely on clean javascript and server-side services, take and OO approach 
using a js framework and use jquery!</li>
</ol>]]></content:encoded>
	</item>
	<item>
		<title>Comment on Closures vs Objects: FIGHT by Objects vs Closures &#124; phato.blog`</title>
		<link>http://skilldrick.co.uk/2011/09/closures-vs-objects-fight/comment-page-1/#comment-7863</link>
		<dc:creator>Objects vs Closures &#124; phato.blog`</dc:creator>
		<pubDate>Tue, 10 Jan 2012 06:48:28 +0000</pubDate>
		<guid isPermaLink="false">http://skilldrick.co.uk/?p=1420#comment-7863</guid>
		<description>&lt;p&gt;[...] ออริจินัลโพสจาก Skilldrick [...]&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>[...] ออริจินัลโพสจาก Skilldrick [...]</p>]]></content:encoded>
	</item>
	<item>
		<title>Comment on 2011 by Skilldrick &#187; 2012</title>
		<link>http://skilldrick.co.uk/2011/01/2011/comment-page-1/#comment-7497</link>
		<dc:creator>Skilldrick &#187; 2012</dc:creator>
		<pubDate>Mon, 02 Jan 2012 18:32:45 +0000</pubDate>
		<guid isPermaLink="false">http://skilldrick.co.uk/?p=644#comment-7497</guid>
		<description>&lt;p&gt;[...] 2012  January 2nd, 2012 Skilldrick Leave a comment Go to comments    It&#8217;s time for another one of those self-indulgent &#8220;what am I going to do with the next year?&#8221; posts. I can&#8217;t believe it&#8217;s been a whole year since the last one. [...]&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>[...] 2012  January 2nd, 2012 Skilldrick Leave a comment Go to comments    It&#8217;s time for another one of those self-indulgent &#8220;what am I going to do with the next year?&#8221; posts. I can&#8217;t believe it&#8217;s been a whole year since the last one. [...]</p>]]></content:encoded>
	</item>
	<item>
		<title>Comment on Three years on by aver</title>
		<link>http://skilldrick.co.uk/2011/10/three-years-on/comment-page-1/#comment-6312</link>
		<dc:creator>aver</dc:creator>
		<pubDate>Thu, 01 Dec 2011 00:28:36 +0000</pubDate>
		<guid isPermaLink="false">http://skilldrick.co.uk/?p=1435#comment-6312</guid>
		<description>&lt;p&gt;Nice story you have (here and in your &quot;finding a passion&quot; post).&lt;/p&gt;

&lt;p&gt;I started to learn to program about two years ago. At the time, I didn&#039;t even know what a variable was, but I always had a sense of wonder about how computers and the internet worked; it all seemed like magic.&lt;/p&gt;

&lt;p&gt;For the first year I worked really hard, and I could comfortably program.  But then my motivation seemed to drop. The field was still interesting to me, but I found that programming was causing me to spend most of my time alone in a darkened room. I had a lot of tech knowledge, but my life in general had become less interesting.&lt;/p&gt;

&lt;p&gt;Perhaps I could restart my programming journey, this time being sure to take more breaks and get out more!&lt;/p&gt;

&lt;p&gt;Good luck in San Francisco.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Nice story you have (here and in your &#8220;finding a passion&#8221; post).</p>

<p>I started to learn to program about two years ago. At the time, I didn&#8217;t even know what a variable was, but I always had a sense of wonder about how computers and the internet worked; it all seemed like magic.</p>

<p>For the first year I worked really hard, and I could comfortably program.  But then my motivation seemed to drop. The field was still interesting to me, but I found that programming was causing me to spend most of my time alone in a darkened room. I had a lot of tech knowledge, but my life in general had become less interesting.</p>

<p>Perhaps I could restart my programming journey, this time being sure to take more breaks and get out more!</p>

<p>Good luck in San Francisco.</p>]]></content:encoded>
	</item>
	<item>
		<title>Comment on Closures vs Objects: FIGHT by Skilldrick</title>
		<link>http://skilldrick.co.uk/2011/09/closures-vs-objects-fight/comment-page-1/#comment-5673</link>
		<dc:creator>Skilldrick</dc:creator>
		<pubDate>Thu, 03 Nov 2011 10:57:31 +0000</pubDate>
		<guid isPermaLink="false">http://skilldrick.co.uk/?p=1420#comment-5673</guid>
		<description>&lt;p&gt;&lt;a href=&quot;#comment-5671&quot; rel=&quot;nofollow&quot;&gt;@Dmitry Pashkevich &lt;/a&gt; That&#039;s true, although I generally don&#039;t use a debugger for debugging - I prefer to just use &lt;code&gt;console.log&lt;/code&gt; - so that doesn&#039;t really affect me. Which reminds me, I&#039;ve been meaning to do a post about print statements vs debuggers for a while, thanks!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p><a href="#comment-5671" rel="nofollow">@Dmitry Pashkevich </a> That&#8217;s true, although I generally don&#8217;t use a debugger for debugging &#8211; I prefer to just use <code>console.log</code> &#8211; so that doesn&#8217;t really affect me. Which reminds me, I&#8217;ve been meaning to do a post about print statements vs debuggers for a while, thanks!</p>]]></content:encoded>
	</item>
	<item>
		<title>Comment on Closures vs Objects: FIGHT by Dmitry Pashkevich</title>
		<link>http://skilldrick.co.uk/2011/09/closures-vs-objects-fight/comment-page-1/#comment-5671</link>
		<dc:creator>Dmitry Pashkevich</dc:creator>
		<pubDate>Thu, 03 Nov 2011 10:48:12 +0000</pubDate>
		<guid isPermaLink="false">http://skilldrick.co.uk/?p=1420#comment-5671</guid>
		<description>&lt;p&gt;Good insight!&lt;/p&gt;

&lt;p&gt;I would add to the penultimate paragraph (about third-party access to your objects) that for same reasons closures are also much more unpleasant to debug without modifying the source code. 
No-one will ever mess with your internal implementation nor debug your plugin if it has issues.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Good insight!</p>

<p>I would add to the penultimate paragraph (about third-party access to your objects) that for same reasons closures are also much more unpleasant to debug without modifying the source code. 
No-one will ever mess with your internal implementation nor debug your plugin if it has issues.</p>]]></content:encoded>
	</item>
	<item>
		<title>Comment on A brief introduction to closures by Skilldrick</title>
		<link>http://skilldrick.co.uk/2010/11/a-brief-introduction-to-closures/comment-page-1/#comment-5462</link>
		<dc:creator>Skilldrick</dc:creator>
		<pubDate>Wed, 26 Oct 2011 08:39:18 +0000</pubDate>
		<guid isPermaLink="false">http://skilldrick.co.uk/?p=569#comment-5462</guid>
		<description>&lt;p&gt;&lt;a href=&quot;#comment-5450&quot; rel=&quot;nofollow&quot;&gt;@Vlad &lt;/a&gt; Hi Vlad, I&#039;ve done my best to fix your HTML.&lt;/p&gt;

&lt;p&gt;I can&#039;t reply to your entire comment right now, but to answer the first question about lexical environment:&lt;/p&gt;

&lt;p&gt;You&#039;re confusing things a bit by talking about &lt;code&gt;g&lt;/code&gt; being &#039;copied&#039; into the other function. Code in &lt;code&gt;f&lt;/code&gt; has access to &lt;code&gt;g&lt;/code&gt; both times. The first time is because &lt;code&gt;g&lt;/code&gt; is in &lt;code&gt;f&lt;/code&gt;&#039;s parent scope. The second time is because &lt;code&gt;g&lt;/code&gt; is in &lt;code&gt;f&lt;/code&gt;&#039;s scope.&lt;/p&gt;

&lt;p&gt;What happens, when you call &lt;code&gt;g()&lt;/code&gt; within &lt;code&gt;f&lt;/code&gt; is this: In the first case, the interpreter will look for a definition  of &lt;code&gt;g&lt;/code&gt; within &lt;code&gt;f&lt;/code&gt;. It won&#039;t find it, so it looks in the parent scope, which is where &lt;code&gt;g&lt;/code&gt; is defined. Otherwise, it would look to the next containing scope and so on until it reaches the global scope (the top level).&lt;/p&gt;

&lt;p&gt;In the second case, the interpreter will find the definition of &lt;code&gt;g&lt;/code&gt; within &lt;code&gt;f&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The important thing is though, that &lt;code&gt;g&lt;/code&gt; is not &#039;copied&#039; into &lt;code&gt;f&lt;/code&gt;. There is only the one &lt;code&gt;g&lt;/code&gt;, and the interpreter searches up the scope chain until it is found.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;It seems that you have some fundamental misconceptions about the way JavaScript works - I&#039;d recommend you read &lt;a href=&quot;http://eloquentjavascript.net/&quot; rel=&quot;nofollow&quot;&gt;Eloquent JavaScript&lt;/a&gt;. Good luck!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p><a href="#comment-5450" rel="nofollow">@Vlad </a> Hi Vlad, I&#8217;ve done my best to fix your HTML.</p>

<p>I can&#8217;t reply to your entire comment right now, but to answer the first question about lexical environment:</p>

<p>You&#8217;re confusing things a bit by talking about <code>g</code> being &#8216;copied&#8217; into the other function. Code in <code>f</code> has access to <code>g</code> both times. The first time is because <code>g</code> is in <code>f</code>&#8216;s parent scope. The second time is because <code>g</code> is in <code>f</code>&#8216;s scope.</p>

<p>What happens, when you call <code>g()</code> within <code>f</code> is this: In the first case, the interpreter will look for a definition  of <code>g</code> within <code>f</code>. It won&#8217;t find it, so it looks in the parent scope, which is where <code>g</code> is defined. Otherwise, it would look to the next containing scope and so on until it reaches the global scope (the top level).</p>

<p>In the second case, the interpreter will find the definition of <code>g</code> within <code>f</code>.</p>

<p>The important thing is though, that <code>g</code> is not &#8216;copied&#8217; into <code>f</code>. There is only the one <code>g</code>, and the interpreter searches up the scope chain until it is found.</p>

<hr />

<p>It seems that you have some fundamental misconceptions about the way JavaScript works &#8211; I&#8217;d recommend you read <a href="http://eloquentjavascript.net/" rel="nofollow">Eloquent JavaScript</a>. Good luck!</p>]]></content:encoded>
	</item>
	<item>
		<title>Comment on A brief introduction to closures by Vlad</title>
		<link>http://skilldrick.co.uk/2010/11/a-brief-introduction-to-closures/comment-page-1/#comment-5451</link>
		<dc:creator>Vlad</dc:creator>
		<pubDate>Wed, 26 Oct 2011 04:11:21 +0000</pubDate>
		<guid isPermaLink="false">http://skilldrick.co.uk/?p=569#comment-5451</guid>
		<description>&lt;p&gt;&lt;a href=&quot;#comment-5450&quot; rel=&quot;nofollow&quot;&gt;@Vlad &lt;/a&gt; 
I didn&#039;t know HTML would be parsed. Sorry. To correct the paragraph that has been turned in to a link:&lt;/p&gt;

&lt;p&gt;I assumed the value of i would be taken in the first loop as =0 and something like &lt;/p&gt;

&lt;p&gt;[a onclick=&quot;alert(0)&quot;] &lt;/p&gt;

&lt;p&gt;would be inserted into the html right there and then. When the loop repeated, it would insert [a onclick=&quot;alert(1)&quot;] etc. ...&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p><a href="#comment-5450" rel="nofollow">@Vlad </a> 
I didn&#8217;t know HTML would be parsed. Sorry. To correct the paragraph that has been turned in to a link:</p>

<p>I assumed the value of i would be taken in the first loop as =0 and something like </p>

<p>[a onclick="alert(0)"] </p>

<p>would be inserted into the html right there and then. When the loop repeated, it would insert [a onclick="alert(1)"] etc. &#8230;</p>]]></content:encoded>
	</item>
	<item>
		<title>Comment on A brief introduction to closures by Vlad</title>
		<link>http://skilldrick.co.uk/2010/11/a-brief-introduction-to-closures/comment-page-1/#comment-5450</link>
		<dc:creator>Vlad</dc:creator>
		<pubDate>Wed, 26 Oct 2011 04:07:21 +0000</pubDate>
		<guid isPermaLink="false">http://skilldrick.co.uk/?p=569#comment-5450</guid>
		<description>&lt;p&gt;Great article, but a few things needed to be spelled out for newbies like me.&lt;/p&gt;

&lt;p&gt;First, you need to explain what &quot;lexical environment&quot; means. To give you some insight into the newbie mind, I had hastily assumed there is no difference semantically between:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;function g() {}         // g defined outside f and called inside f
function f() { g(); }
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;and &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;function f() { function g() {}; ... } //g defined inside f
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I tended to think that g gets copied into the other function anyway. But based on your examples, I see that is precisely the issue. If a function is defined inside another function, it has access to the variables &quot;above&quot;, but if it&#039;s defined separately, you need to pass the variables to it through parameters from within the outer function, which takes those values &quot;outside&quot; the scope of that function and &quot;remembers&quot; their values by way of separate variables defined inside the external function.&lt;/p&gt;

&lt;p&gt;Also, for a long while, I did not understand that the code of the inner function is executed when the main function is called (i.e. when a click event actually occurs, if it&#039;s an event-handling function). I mistakenly interpreted each instance of the loop as separate and static, with the i value retrieved assigned at the time of the execution of each loop.&lt;/p&gt;

&lt;p&gt;For example, if I were to bind an event to some &lt;code&gt;&lt;a&gt;&lt;/code&gt; element like so:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;a_element.attachEvent(&quot;click&quot;, function () { alert(i); })
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I assumed the value of i would be taken in the first loop as =0 and something like &lt;code&gt;&lt;a onclick=&quot;alert(0)&quot;&gt;&lt;/code&gt; would be inserted into the html right there and then. When the loop repeated, it would insert &lt;code&gt;&lt;a onclick=&quot;alert(1)&quot;&gt;&lt;/code&gt; etc. So I did not understand why the latest value of i could &quot;intrude&quot; on values of i that were already done with. But I see that the i defined in the loop is dynamic. Its value is retrieved at the time of the function call (or the event), which is after the loop has completed.&lt;/p&gt;

&lt;p&gt;The key seems to be that when a function is called and the i variable is accessed from the inner function, the same i is always accessed every time the inner function is called. What you need is to create another variable that can remember each i as it iterates through the loop.&lt;/p&gt;

&lt;p&gt;External function is one way. Alternatively, you can nest the functions and pass the &quot;global i&quot; to the inside function through a parameter, which achieves the same result:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var func = function (i_holder) {
      return function() {
         alert(i_holder);
      }
} (i);   // pass outer i as a parameter inside the function

element.addEvent(&quot;onclick&quot;, func);
&lt;/code&gt;&lt;/pre&gt;
</description>
		<content:encoded><![CDATA[<p>Great article, but a few things needed to be spelled out for newbies like me.</p>

<p>First, you need to explain what &#8220;lexical environment&#8221; means. To give you some insight into the newbie mind, I had hastily assumed there is no difference semantically between:</p>

<pre><code>function g() {}         // g defined outside f and called inside f
function f() { g(); }
</code></pre>

<p>and </p>

<pre><code>function f() { function g() {}; ... } //g defined inside f
</code></pre>

<p>I tended to think that g gets copied into the other function anyway. But based on your examples, I see that is precisely the issue. If a function is defined inside another function, it has access to the variables &#8220;above&#8221;, but if it&#8217;s defined separately, you need to pass the variables to it through parameters from within the outer function, which takes those values &#8220;outside&#8221; the scope of that function and &#8220;remembers&#8221; their values by way of separate variables defined inside the external function.</p>

<p>Also, for a long while, I did not understand that the code of the inner function is executed when the main function is called (i.e. when a click event actually occurs, if it&#8217;s an event-handling function). I mistakenly interpreted each instance of the loop as separate and static, with the i value retrieved assigned at the time of the execution of each loop.</p>

<p>For example, if I were to bind an event to some <code>&lt;a&gt;</code> element like so:</p>

<pre><code>a_element.attachEvent("click", function () { alert(i); })
</code></pre>

<p>I assumed the value of i would be taken in the first loop as =0 and something like <code>&lt;a onclick="alert(0)"&gt;</code> would be inserted into the html right there and then. When the loop repeated, it would insert <code>&lt;a onclick="alert(1)"&gt;</code> etc. So I did not understand why the latest value of i could &#8220;intrude&#8221; on values of i that were already done with. But I see that the i defined in the loop is dynamic. Its value is retrieved at the time of the function call (or the event), which is after the loop has completed.</p>

<p>The key seems to be that when a function is called and the i variable is accessed from the inner function, the same i is always accessed every time the inner function is called. What you need is to create another variable that can remember each i as it iterates through the loop.</p>

<p>External function is one way. Alternatively, you can nest the functions and pass the &#8220;global i&#8221; to the inside function through a parameter, which achieves the same result:</p>

<pre><code>var func = function (i_holder) {
      return function() {
         alert(i_holder);
      }
} (i);   // pass outer i as a parameter inside the function

element.addEvent("onclick", func);
</code></pre>]]></content:encoded>
	</item>
</channel>
</rss>

