fail-fast object destructuring

Erik Arvidsson erik.arvidsson at gmail.com
Mon Jun 25 09:33:41 PDT 2012


On Mon, Jun 25, 2012 at 9:14 AM, Brendan Eich <brendan at mozilla.org> wrote:
> I'm ok with this even though it is not compatible with what we've
> implemented and user-tested for almost six years, but I want (b) as part of
> the deal. We have code that will use ?-prefixing.

I want this (a) too but I don't think (b) is worth the syntax.
Defaulting to undefined is a better pattern and it encourages people
to default to what they want instead of adding one more line of code.

With (b) I can see code like this:

var {?a} = someObject;
if (typeof a === 'undefined')
  a = defaultValue;

Clearly, an anti pattern over

var {a = defaultValue} = someObject;

-- 
erik


More information about the es-discuss mailing list