功能与新功能的区别 [英] difference between Function and new Function
问题描述
我有时看到人们这样做 Function('alert(hi)')
hi)')
I sometimes see people doing this Function('alert("hi")')
and sometimes they do new Function('alert("hi")')
两者之间是否有区别?
推荐答案
规范(第127页)说,相同。
The spec (page 127) says they're identical.
15.3.1.1函数(p1,p2,...,pn,body)
$ b b当
Function
函数调用
时,有一些参数p1,p2,...,pn,
body(其中n可能为0,也就是
没有p参数,并且其中
body也可能不被提供),则采取以下步骤的
:
15.3.1.1 Function (p1, p2, … , pn, body)
When the
Function
function is called with some arguments p1, p2, … , pn, body (where n might be 0, that is, there are no "p" arguments, and where body might also not be provided), the following steps are taken:
- 创建并返回一个新的Function对象,就像标准的内置的
构造函数在一个带有相同参数的新的
表达式中使用
15.3.2.1)。
应该不惜一切代价避免 Function
构造函数。
它需要 eval
到它; eval
是邪恶的,太慢了。
However, you should avoid the Function
cinstructor at all costs.
It needs to eval
the string you pass to it; eval
is evil, and slow too.
这篇关于功能与新功能的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!