2 ms·
Serializing a regexp as, say, "/foo/" would mean emitting alleged JSON that doesn't conform to the JSON grammar in the spec, and that existing JSON parsers migh
by gjm11 17y ago
Serializing a regexp as, say, "/foo/" would mean emitting alleged JSON that doesn't conform to the JSON grammar in the spec, and that existing JSON parsers might be completely unable to do anything with. It might make some sense to change the spec to include regexp literals, but while the spec says what it does it would be unresponsible for any browser's stringify implementation to emit things that others' parse implementations might barf on.
(It's a pity that JSON isn't more easily extensible in a backward-compatible manner. On the other hand, it's not clear how that could have been enabled without breaking the it's-just-a-subset-of-JS-literal-syntax principle.)