destructuring: as patterns?

Brendan Eich brendan at
Fri Apr 20 14:28:38 PDT 2012

Brendan Eich wrote:
> Dave suggested making the first case, let {x} = {}, throw, and 
> requiring ? as a pattern modifier (I suggested prefix):
> let {?x} = {}; // x is undefined, no throw
> let {y} = {};  // throw

I forgot to mention something Dave noticed. Should

   let {?x:{y}} = {};

This too would not throw, rather it would bind y to undefined -- unlike 
the get-undefined-and-then-fail-trying-to-get-y-from-it approach of 
destructuring as implemented in SpiderMonkey and Rhino (based on ES4, 
then ES6 drafts).

So ? as pattern prefix is a deep opt-in flag. Thoughts?


More information about the es-discuss mailing list