RegExp('hi')
和有什么区别和new RegExp('hi')
?
new
是吗?关键字在这里做什么?
最佳答案
完全相同
The
RegExp
constructor is the%RegExp%
intrinsic object and the initial value of theRegExp
property of the global object. WhenRegExp
is called as a function rather than as a constructor, it creates and initializes a newRegExp
object. Thus the function callRegExp(…)
is equivalent to the object creation expressionnew RegExp(…)
with the same arguments.
来自http://www.ecma-international.org/ecma-262/6.0/#sec-regexp-constructor
关于JavaScript: `new RegExp(' hi' )` versus ` RegExp ('hi' )`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39215710/