Object dynamic property with or
T.J. Crowder
tj.crowder at farsightsoftware.com
Thu Jun 15 10:32:48 UTC 2017
On Thu, Jun 15, 2017 at 11:19 AM, Matthew Robb <matthewwrobb at gmail.com>
wrote:
> Why not this: `const { a = o.b } = o;`?
That works for the object-specific case from somonek (if he uses
`propertyThree` as his/her variable instead of `myProp`), e.g.:
```js
const myObj = {
propertyOne: 'someValue',
propertyTwo: 'another value'
};
let {propertyThree = myObj.propertyTwo} = myObj;
console.log(propertyThree); // another value
myObj.propertyThree = 'third value';
({propertyThree = myObj.propertyTwo} = myObj);
console.log(propertyThree); // third value
```
Doesn't help in the general case, but does address this specific case.
-- T.J. Crowder
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170615/b9dd35c7/attachment.html>
More information about the es-discuss
mailing list