问题
What is the difference between RegExp('hi') and new RegExp('hi')?
Does the new keyword do anything here?
回答1:
It is identical
The
RegExpconstructor is the%RegExp%intrinsic object and the initial value of theRegExpproperty of the global object. WhenRegExpis called as a function rather than as a constructor, it creates and initializes a newRegExpobject. Thus the function callRegExp(…)is equivalent to the object creation expressionnew RegExp(…)with the same arguments.
From http://www.ecma-international.org/ecma-262/6.0/#sec-regexp-constructor
来源:https://stackoverflow.com/questions/39215710/javascript-new-regexphi-versus-regexphi