4 ms·
(typeof (new (class { class () {} }))) // -> 'object' It seems like we're declaring a class inside of class. Should be and error, however, we get an 'object'
by gattilorenz 9y ago
(typeof (new (class { class () {} }))) // -> 'object'
It seems like we're declaring a class inside of class. Should be and error, however, we get an 'object' string.
Explanation:
Since ECMAScript 5 era, keywords are allowed as property names.
Can anyone explain why allowing keywords as property names seemed a good idea? To me it creates a lot of potential for confusion without providing enough benefits, but I'd like to be... enlightened
- masklinn 9y agoBecause they found out they had little reason not to, and it can be convenient e.g. in Python when messing around with metaprogramming you have to use `cls` or `kls` or `klass` rather than the obvious `class` as a local variable name, just because keywords can't be used in other context. It's even more annoying in JS as e.g. a property named `class` is very common in DOM contexts.