should I drop the 'new' in this function passing regexp?
This question already has an answer here:
RegExp("foo")
and new RegExp("foo")
do the same thing:
15.10.3 The RegExp Constructor Called as a Function
15.10.3.1 RegExp(pattern, flags)
If pattern is an object R whose [[Class]] internal property is "RegExp" and flags is undefined, then return R unchanged. Otherwise call the standard built-in RegExp constructor (15.10.4.1) as if by the expression new RegExp( pattern, flags) and return the object constructed by that constructor.
http://es5.github.io/#x15.10.3
In simpler terms, RegExp(/someRegex/)
returns that regex, while RegExp("someString")
creates a new regexp from the string, just as new RegExp
does.
上一篇: 新对象,模块中的代码