Refutable destructuring

Brendan Eich brendan at mozilla.com
Fri Aug 16 15:48:48 PDT 2013


Brandon Benvie wrote:
> On 8/16/2013 2:08 PM, Domenic Denicola wrote:
>> Actually, I think it'd be fantastic to have an easy way to 
>> communicate required parameters in an options object.
>
> I agree and this is why I was a fan of Axel's +/! "this is required" 
> prefix.

Having such syntax available would address the required-parameters 
use-case, but still leave a split between destructuring 
assignment/binding and any future match syntax that uses patterns too.

> One of the reason's JS is so popular is because hard failure is 
> opt-in. That is: by default the language will not punish you for 
> mistakes made as a noob/while developing. You can access a 
> non-existent property, for example, without it destroying the whole 
> program. This is, of course, also a source of subtle and hard to 
> diagnose bugs. But, on balance, I think it's worth it for what JS is 
> meant to do.

Fail-soft in this regard is a crucial feature of the web and its 
"versioning is an anti-pattern" -- by which I mean object detection.

> That doesn't mean we can't have opt-in strictness, though. This is why 
> I love Axel's proposal: you *can* opt-in for strictness and get the 
> guarantees you want. This is the same reason TypeScript exists, and 
> has gained such a following. TypeScript is to ECMAScript as refutable 
> destructuring is to Axel's proposal.

Again, this works except in a match construct, where failure to trigger 
next-pattern attempt must be the default.

/be


More information about the es-discuss mailing list