简体   繁体   中英

What is "runtime compilation" in Javascript?

I'm reading this article on regular expressions, and it says "Using the constructor function provides runtime compilation of the regular expression". It then says "Use the constructor function when you know the regular expression pattern will be changing". What I want to know is, what exactly is runtime compilation in Javascript?

It means that when you use the /ab+c/; the regexp es compiled when the script is loaded and before it's used but if you use the constructor it is compiled just before that line is executed.

Using the constructor is useful, for example, when you want to build the regexp using a variable: new RegExp('ab+' + value);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM