Tom Van Cutsem wrote:
2012/10/16 Herby Vojčík <[email protected] <mailto:[email protected]>>
I see two solutions:
- add something to the freeze, seal, preventExtensions family which
would set an object to the fail-fast [[Get]] state.
- use a Proxy in the proto chain to trap the unknown [[Get]] and
throw early
Do you think this needs a solution at all? If yes, which option would
you favour?
The second option is easy to accomplish but pretty invasive since it
requires you to inherit from a particular object. If you have an
abstraction that already inherits from something else, you're hosed.
Personally, I'm not convinced this is a big enough problem to warrant
another "mode" for Javascript objects.
This has come up in TC39, and on this list. Waldemar would like a way
(not the default) to seal a class so typo'ed member names throw:
https://mail.mozilla.org/pipermail/es-discuss/2012-May/022837.html
However, since then, I recall hearing Waldemar say that the private
at-name syntax in classes (for him) made the case that maximally minimal
classes hang together in ES6, without any "const class" or sealed class
option.
I agree it's not a big enough problem to add a "mode" or anything like
that. Opt-in by class could be helpful. TypeScript has its optional
member syntax (?:) and can give warnings. It seems to me this kind of
tool-time help might be enough.
/be
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss