<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>岁月如歌 &#187; eval</title>
	<atom:link href="http://lifesinger.org/blog/tag/eval/feed/" rel="self" type="application/rss+xml" />
	<link>http://lifesinger.org/blog</link>
	<description>关注用户体验、前端开发，记录生活点滴、岁月足迹。</description>
	<lastBuildDate>Mon, 06 Sep 2010 15:05:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>邪恶的eval和new Function</title>
		<link>http://lifesinger.org/blog/2009/02/eval-new-function-evil/</link>
		<comments>http://lifesinger.org/blog/2009/02/eval-new-function-evil/#comments</comments>
		<pubDate>Tue, 10 Feb 2009 21:29:55 +0000</pubDate>
		<dc:creator>lifesinger</dc:creator>
				<category><![CDATA[开发]]></category>
		<category><![CDATA[eval]]></category>
		<category><![CDATA[function]]></category>

		<guid isPermaLink="false">http://lifesinger.org/blog/?p=1242</guid>
		<description><![CDATA[代码： // 友善提醒：为了你的手指安全，请在Chrome下运行 'alert("hello")'.replace(/.+/, eval); 'alert("hello")'.replace(/.+/, function(m){new Function(m)();}); var i = 0; eval(new Array(101).join('alert(++i);')); var i = 0; new Function(new Array(101).join('alert(++i);'))(); 解释： string.replace(regexp, replacement): replacement可以是function. In this case, the function is invoked for each match, and the string it returns is used as the replacement text. new Function(argument_names..., body): 注意参数中的body. 这样，用new Function('body')(), 也可以像eval一样动态执行代码。 array.join(separator): 这个最简单，不多说。在这里，巧妙的用来解决了一个无聊问题：写段代码，运行后打印出从1到100的整数，不允许使用循环、跳转和递归。 [...]]]></description>
			<content:encoded><![CDATA[<p>代码：</p>
<pre>
// 友善提醒：为了你的手指安全，请在Chrome下运行
'alert("hello")'.replace(/.+/, eval);
'alert("hello")'.replace(/.+/, function(m){new Function(m)();});

var i = 0; eval(new Array(101).join('alert(++i);'));
var i = 0; new Function(new Array(101).join('alert(++i);'))();
</pre>
<p>解释：</p>
<ol>
<li><code>string.replace(regexp, replacement)</code>: replacement可以是function. In this case, the function is invoked for each match, and the string it returns is used as the replacement text. </li>
<li><code>new Function(argument_names..., body)</code>: 注意参数中的body. 这样，用<code>new Function('body')()</code>, 也可以像eval一样动态执行代码。</li>
<li><code>array.join(separator)</code>: 这个最简单，不多说。在这里，巧妙的用来解决了一个无聊问题：写段代码，运行后打印出从1到100的整数，不允许使用循环、跳转和递归。</li>
</ol>
<p>这些代码可以干什么？可以肯定的是可以干很多猥琐的事。具体是啥呢，自己想啰。</p>
]]></content:encoded>
			<wfw:commentRss>http://lifesinger.org/blog/2009/02/eval-new-function-evil/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
