3 ms·
The ECMAScript spec is weird. One example: in ES5 RegExp.prototype was itself a RegExp, in ES6 it became not a RegExp but just an Object, and in ES7 it stayed a
by ridiculous_fish 9y ago
The ECMAScript spec is weird. One example: in ES5 RegExp.prototype was itself a RegExp, in ES6 it became not a RegExp but just an Object, and in ES7 it stayed an Object but all of the RegExp.prototype methods have to specially check if `this` is RegExp.prototype, thereby pretending to be a RegExp, without actually being one.
Why does the spec have this churn?
- spiralx 9y agoI suspect it might have something to do with allowing developers to extend the built-in types - I know that changes were made between ES5 and ES6 to allow subclassing Array, could well be the same issue. See Symbol.species for instance. Wait, it's actually most likely because in ES6 you can use `new RegExp()` as well as `RegExp()` to create a new object.