Why do two regex literals in my Javascript vary on a property? -
i read in javascript: parts douglas crockford javascript regular expression literals share same object. if so, how come these 2 regex literals vary in lastindex
property?
var = /a/g; var b = /a/g; a.lastindex = 3; document.write(b.lastindex);
0 outputted opposed 3.
section 7.8.5 of ecmascript documentation makes quite clear 2 different objects:
7.8.5 regular expression literals
regular expression literal input element converted regexp object (see 15.10) each time literal evaluated. 2 regular expression literals in program evaluate regular expression objects never compare === each other if 2 literals' contents identical. regexp object may created @ runtime new regexp (see 15.10.4) or calling regexp constructor function (15.10.3).
Comments
Post a Comment