should I drop the 'new' in this function passing regexp?

This question already has an answer here:

  • What is the 'new' keyword in JavaScript? 13 answers

  • 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.

    链接地址: http://www.djcxy.com/p/40864.html

    上一篇: 新对象,模块中的代码

    下一篇: 我应该在这个函数中传递'new'来传递regexp吗?