3 ms·
> Can't we simply have a type-system for JavaScript that only prohibits undefined field access and nothing else? Yes, but it's not easy for cultural reasons.
by lisper 9y ago
> Can't we simply have a type-system for JavaScript that only prohibits undefined field access and nothing else?
Yes, but it's not easy for cultural reasons. In order to detect undefined field access you need to know what the fields are at compile time, which is to say, you need classes. Javascript's original design was based on prototypes, which have a fundamental "impedance mismatch" with classes. It's possible to layer classes on top of prototypes. That's actually not so hard, you can find a lot of user-level implementations of classes out there (e.g. https://github.com/neverblued/js-clos https://github.com/neverblued/js-clos). But to make that part of the language so that compilers will be aware of it you'd have to get the community to agree on a design, and that is very challenging. But it's a political problem, not a technical one.