Allen Wirfs-Brock (2013-08-16T19:56:23.000Z)
domenic at domenicdenicola.com (2013-08-19T05:07:22.904Z)
On Aug 16, 2013, at 12:18 PM, Dmitry Soshnikov wrote: > In JS, there is mutation and assignment. And pattern matching here is secondary. Initially exactly the destructuring plays main role here. And again, for the current foo.nonExisting being undefined use-case is also leans towards not throwing. In JS we also have binding initialization: ```js let x; // outer x { // //in this zone outer 'x' is shadowed by the uninitialized inner 'x'. any reference to 'x' will throw // let x=42; //initialize the inner 'x' binding to the value 42 // //In this zone a reference to 'x' returns the current value of inner 'x' // } ``` In ES6 a reference to 'x' is always valid if it is dominated by a single name lexical declaration of 'x'. If we want to preserve this for destructuring initialized bindings we must deal with: ```js let {x} = {}; ``` More specifically, we don't want to allow control to pas such a declaration without initializing the local binding for 'x'. So our alternatives are initialize 'x' to undefined as if it was a single name binding without an initializer or throwing to stop forward progress. I think either would be acceptable. However, I think throwing is like to reveal bugs that might otherwise be missed prior to deployment and as a code reader I would prefer to encounter ```js let {x=undefined) = {}; ``` which communicates much more clearly that there is an expectation that 'x' may not exist as a property of the RHS.