<?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>《javascript中的引用与闭包》的评论</title>
	<atom:link href="http://www.frontendcodes.com/?feed=rss2&#038;p=28" rel="self" type="application/rss+xml" />
	<link>http://www.frontendcodes.com/?p=28</link>
	<description>路漫漫其修远兮</description>
	<lastBuildDate>Tue, 27 Oct 2020 16:09:08 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
	<item>
		<title>作者：东彦</title>
		<link>http://www.frontendcodes.com/?p=28#comment-12</link>
		<dc:creator>东彦</dc:creator>
		<pubDate>Mon, 24 Jan 2011 08:10:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.frontendcodes.com/?p=28#comment-12</guid>
		<description>柠檬很给力，我表示对这个example相当有好感</description>
		<content:encoded><![CDATA[<p>柠檬很给力，我表示对这个example相当有好感</p>
]]></content:encoded>
	</item>
	<item>
		<title>作者：花语</title>
		<link>http://www.frontendcodes.com/?p=28#comment-9</link>
		<dc:creator>花语</dc:creator>
		<pubDate>Sun, 23 Jan 2011 03:51:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.frontendcodes.com/?p=28#comment-9</guid>
		<description>很好很给力,檬檬!</description>
		<content:encoded><![CDATA[<p>很好很给力,檬檬!</p>
]]></content:encoded>
	</item>
	<item>
		<title>作者：最爱柠檬</title>
		<link>http://www.frontendcodes.com/?p=28#comment-8</link>
		<dc:creator>最爱柠檬</dc:creator>
		<pubDate>Sat, 22 Jan 2011 15:36:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.frontendcodes.com/?p=28#comment-8</guid>
		<description>li[i].onclick=(function(i){
return function(){alert(i);}
})(i);

相当于
var func=function(_i){
var fn=function(){alert(_i);}
return fn;
}
var callback=func(i);
li[i].onclick=callback;

li的onclick事件调用了callback，而callback又引用了func里面的函数，形成了闭包。由于闭包使得i被保存在闭包函数中</description>
		<content:encoded><![CDATA[<p>li[i].onclick=(function(i){<br />
return function(){alert(i);}<br />
})(i);</p>
<p>相当于<br />
var func=function(_i){<br />
var fn=function(){alert(_i);}<br />
return fn;<br />
}<br />
var callback=func(i);<br />
li[i].onclick=callback;</p>
<p>li的onclick事件调用了callback，而callback又引用了func里面的函数，形成了闭包。由于闭包使得i被保存在闭包函数中</p>
]]></content:encoded>
	</item>
	<item>
		<title>作者：MK</title>
		<link>http://www.frontendcodes.com/?p=28#comment-7</link>
		<dc:creator>MK</dc:creator>
		<pubDate>Sat, 22 Jan 2011 15:15:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.frontendcodes.com/?p=28#comment-7</guid>
		<description>&lt;code&gt;
for(var i=0,l=li.length;i&lt;l;i++){
  li[i].onclick=(function(_i){
    return function(){alert(_i);}
  })(i);
}
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p><code><br />
for(var i=0,l=li.length;i&lt;l;i++){<br />
  li[i].onclick=(function(_i){<br />
    return function(){alert(_i);}<br />
  })(i);<br />
}<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>作者：ant</title>
		<link>http://www.frontendcodes.com/?p=28#comment-6</link>
		<dc:creator>ant</dc:creator>
		<pubDate>Sat, 22 Jan 2011 15:10:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.frontendcodes.com/?p=28#comment-6</guid>
		<description>檬帝,能解释下面这个代码是哪个引用引个么?都是叫i,能画个图么?
var li=document.getElementsByTagName(“li”);
for(var i=0,l=li.length;i&lt;l;i++){
li[i].onclick=(function(i){
return function(){alert(i);}
})(i);
}</description>
		<content:encoded><![CDATA[<p>檬帝,能解释下面这个代码是哪个引用引个么?都是叫i,能画个图么?<br />
var li=document.getElementsByTagName(“li”);<br />
for(var i=0,l=li.length;i&lt;l;i++){<br />
li[i].onclick=(function(i){<br />
return function(){alert(i);}<br />
})(i);<br />
}</p>
]]></content:encoded>
	</item>
</channel>
</rss>
