obj2 would be { one: 1, two: 2 }. This syntax is visually similar to
the getter/setter syntax. This should also support the computed property
approach:
const { three, ...obj2 } = obj1; // has the side-effect of creating
unnecessary variable `three`.
delete obj2.three; // seems odd to create an object to then reach-in and
remove things.
It is worth noting that const obj2 = { ...obj1, three: undefined } is not
the same thing, as obj2.hasOwnProperty('three') would still return true.
With spread properties, it would be great to be able to remove specific
properties:
```js
const obj1 = { one: 1, two: 2, three: 3 };
const obj2 = {
...obj1,
delete three // <-- new syntax
};
```
`obj2` would be `{ one: 1, two: 2 }`. This syntax is visually similar to
the getter/setter syntax. This should also support the computed property
approach:
```js
const propName="three";
const obj1 = { one: 1, two: 2, [propName]: 3 };
const obj2 = { ...obj1, delete [propName] };
```
There are 2 ways of currently doing this:
```js
const { three, ...obj2 } = obj1; // has the side-effect of creating
unnecessary variable `three`.
delete obj2.three; // seems odd to create an object to then reach-in and
remove things.
```
It is worth noting that `const obj2 = { ...obj1, three: undefined }` is not
the same thing, as `obj2.hasOwnProperty('three')` would still return true.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180210/aa039c4a/attachment-0001.html>
With spread properties, it would be great to be able to remove specific properties:
const obj1 = { one: 1, two: 2, three: 3 }; const obj2 = { ...obj1, delete three // <-- new syntax };
obj2
would be{ one: 1, two: 2 }
. This syntax is visually similar to the getter/setter syntax. This should also support the computed property approach:const propName="three"; const obj1 = { one: 1, two: 2, [propName]: 3 }; const obj2 = { ...obj1, delete [propName] };
There are 2 ways of currently doing this:
const { three, ...obj2 } = obj1; // has the side-effect of creating unnecessary variable `three`. delete obj2.three; // seems odd to create an object to then reach-in and remove things.
It is worth noting that
const obj2 = { ...obj1, three: undefined }
is not the same thing, asobj2.hasOwnProperty('three')
would still return true.