亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

eval和new Function使用介紹

 更新時(shí)間:2012年12月27日 15:16:41   投稿:mdxy-dxy  
這些代碼可以干什么?可以肯定的是可以干很多的事

代碼:

復(fù)制代碼 代碼如下:

// 友善提醒:為了你的手指安全,請(qǐng)?jiān)贑hrome下運(yùn)行
'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);'))();


解釋:
1、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.

2、new Function(argument_names..., body): 注意參數(shù)中的body. 這樣,用new Function('body')()
, 也可以像eval一樣動(dòng)態(tài)執(zhí)行代碼。

3、array.join(separator): 這個(gè)最簡(jiǎn)單,不多說(shuō)。在這里,巧妙的用來(lái)解決了一個(gè)無(wú)聊問(wèn)題:寫(xiě)段代碼,運(yùn)行后打印出從1到100的整數(shù),不允許使用循環(huán)、跳轉(zhuǎn)和遞歸。

這些代碼可以干什么?可以肯定的是可以干很多的事。具體是啥呢,自己想啰。

相關(guān)文章

最新評(píng)論