Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在阅读这篇关于正则表达式的文章,它说“使用构造函数提供正则表达式的运行时编译”。然后它说“当您知道正则表达式模式将发生变化时使用构造函数”。我想知道的是,Javascript 中的运行时编译到底是什么?
这意味着当您使用在/ab+c/;加载脚本时和使用之前编译的 regexp es,但如果您使用构造函数,它会在执行该行之前编译。
/ab+c/;
使用构造函数很有用,例如,当您想使用变量构建正则表达式时:new RegExp('ab+' + value);
new RegExp('ab+' + value);