[Fwd: Fail-fast on non-existing [[Get]]]
wycats at gmail.com
Tue Oct 16 14:14:23 PDT 2012
On Tue, Oct 16, 2012 at 12:51 PM, Herby Vojčík <herby at mailbox.sk> wrote:
> This did not get to the list, reposting...
> -------- Original Message --------
> From: Herby Vojčík <herby at mailbox.sk>
> Subject: Fail-fast on non-existing [[Get]]
> Date: Fri, 12 Oct 2012 22:42:05 +0200
> To: ECMAScript discussion <es-discuss at mozilla.org>
> I have just looked the video on channel9 between Lars Bak and Anders
> Hejlsberg, and it gave me one idea.
> It seems people sometimes worry about (basically because of a typo) that
> they [[Get]] a non-existing property but as it stands, it just returns
> undefined and goes happily on.
> 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
Using a proxy for your own objects to throw seems reasonable, but see below
for breakage to existing JS patterns. Adding it globally (via
Object.protoype.__proto__) would almost certainly break other JS code on
Consider this very common pattern:
obj.foo = obj.foo || bar;
As a matter of practice, lots of JS code relies on the soft-fail behavior,
for good reason, and trying to change that behavior would not likely result
in happiness for consumers of the code that introduced this change.
> Do you think this needs a solution at all? If yes, which option would
> you favour?
> P.S.: In the latter case, I see the possibility of putting
> ClosedFormObject (or whatever name) constructor function which would
> have a proxy for a .prototype just one step below Object, and let
> classes that would want to throw on default-undefined-[[Get]] just
> derive from that or its ancestors. Do you think this is minimal enough
> so it can be put directly into language (if the solution does not have
> some flaws which are not apparent to me)?
> es-discuss mailing list
> es-discuss at mozilla.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss