fail-fast object destructuring

Andreas Rossberg rossberg at
Tue Jun 26 10:39:18 PDT 2012

On 25 June 2012 19:23, Allen Wirfs-Brock <allen at> wrote:
> 3) Again we have a internal consistency issue:
>   let myFoo = {a:0,b:1}.foo;
> vs
>   let {foo: myFoo} = {a:0,b:1};
> why should one work and the other fail?  The general rule of JS is that accessing a missing property returns undefined. Whether or not you think it is a good rule, it's the way the core or the language works and it can't change.  It's also an easy rule for anybody to learn.  Making exceptions to that rule just makes the language less internally consistent,  harder to learn, and more complex. I don't think we should do it.

I agree that consistency is an important consideration, but it can cut
many ways.

In particular, if there is at least some consensus that we might want
to have pattern matching at a later point, then we might want to
ensure reasonable consistency between destructuring and pattern
matching as well. Frankly, I cannot see how that can be achieved with
destructuring that is irrefutable by default (except for some corner
cases where it isn't, a minor inconsistency on its own). The potential
inconsistency lurking there will likely be much bigger and more
confusing than the rather smallish issue we are discussing here.

(And that is leaving aside all usability considerations for a moment.)


More information about the es-discuss mailing list