Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Using object rest properties to immutably delete multiple keys in runtime #63

Open
liyuanqiu opened this issue Jul 9, 2018 · 1 comment

Comments

@liyuanqiu
Copy link

We know we can get the rest entries of an object:

let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };
x; // 1
y; // 2
z; // { a: 3, b: 4 }

But if the x, y is in an array, for example [ 'x', 'y' ], generated in runtime, I don't know those keys when coding, maybe we need this kind of syntax:

const keys = [ 'x', 'y' ];
// syntax error here, some new syntax is needed
let { ...keys, ...z } = { x: 1, y: 2, a: 3, b: 4 };
x; // 1
y; // 2
z; // { a: 3, b: 4 }
@hax
Copy link
Member

hax commented Jul 9, 2018

@liyuanqiu As lexical scope, all identifiers have to be declared first. So there is no way to magically create x y unless we introduce dynamic scope (like obsolete with statement in non-strict ES5).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants