fail-fast object destructuring (don't add more slop to sloppy mode)

Herby Vojčík herby at mailbox.sk
Wed Jan 2 09:52:38 PST 2013



Brendan Eich wrote:
> Herby Vojčík wrote:
>> Then it naturally follows that you can as well do `let {must:must,
>> ?may:may} = o` which can be shortened.
>
> Yes, that was the syntax we talked about earlier this year, but I think
> CoffeeScript and TypeScript make a case for suffix-?.
>
>> And it can go deeper, since it is Nil.
>
> What is Nil? There is no requirement with ? in the pattern language (on
> the LHS) for the RHS to be of any particular type.
>
> I like Nil, and it may help rescue ?. the existential operator strawman.
> But that is in the expression language, not in the pattern language.

I like not to make things unnecessarily disjoint. Here I see the 
possibility of having pattern language (in future patterns as well as in 
present destructuring) having same semantics as the expression language 
_with_throwing_on_nonexistent_property_ (that is what you asked in this 
thread, unless I did not understand).

That is, these are identical, except the syntax:

	r = o.p.q	{p: {q: r}} = o
	r = o.?p.q	{?p: {q: r}} = o
	P=o.p; Q=o.?q	{p: P, ?q: Q} = o

With "it can go deeper, since it is Nil" I meant the second line, where 
(o.?p) produces Nil, so o.?p.q being Nil.q produces Nil as well, without 
throw.

> /be

Herby


More information about the es-discuss mailing list