邪恶的eval和new Function使用介绍

发布时间:2022-04-17 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了邪恶的eval和new Function使用介绍脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

代码:

复制代码 代码如下:

// 友善提醒:为了你的手指安全,请在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);'))();


解释:
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): 注意参数中的body. 这样,用new Function('body')()
, 也可以像eval一样动态执行代码。

3、array.join(separator): 这个最简单,不多说。在这里,巧妙的用来解决了一个无聊问题:写段代码,运行后打印出从1到100的整数,不允许使用循环、跳转和递归。

这些代码可以干什么?可以肯定的是可以干很多猥琐的事。具体是啥呢,自己想啰。

脚本宝典总结

以上是脚本宝典为你收集整理的邪恶的eval和new Function使用介绍全部内容,希望文章能够帮你解决邪恶的eval和new Function使用介绍所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。