JavaScript: `new RegExp('hi')` versus `RegExp('hi')`? [duplicate]

旧城冷巷雨未停 提交于 2021-02-08 02:13:35

问题


What is the difference between RegExp('hi') and new RegExp('hi')?

Does the new keyword do anything here?


回答1:


It is identical

The RegExp constructor is the %RegExp% intrinsic object and the initial value of the RegExp property of the global object. When RegExp is called as a function rather than as a constructor, it creates and initializes a new RegExp object. Thus the function call RegExp(…) is equivalent to the object creation expression new 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!