Skip to content

Commit 3bf85d7

Browse files
authored
Graveyard the syntax for multiple dynamic keys
1 parent ae26c36 commit 3bf85d7

File tree

1 file changed

+27
-34
lines changed

1 file changed

+27
-34
lines changed

README.md

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,7 @@ const sanitizedOpts = {
7676
};
7777
```
7878

79-
### 5. Excluding Multiple Keys Dynamically
80-
You can exclude an array of keys using the spread operator within the exclusion syntax:
81-
82-
```js
83-
const sanitizedOpts = {
84-
...a,
85-
-[...keysToExclude], // Excludes all keys in the `keysToExclude` array
86-
...b,
87-
};
88-
```
89-
90-
### 6. Using Symbols as Keys
79+
### 5. Using Symbols as Keys
9180
Symbols can also be excluded:
9281

9382
```js
@@ -98,7 +87,7 @@ const sanitizedOpts = {
9887
};
9988
```
10089

101-
### 7. Using Complex Expressions as Keys
90+
### 6. Using Complex Expressions as Keys
10291
Key expressions can be computed on-the-fly:
10392

10493
```js
@@ -203,27 +192,7 @@ const sanitizedOpts = (() => {
203192
})();
204193
```
205194

206-
#### 5. Excluding Multiple Keys Dynamically
207-
Input:
208-
```js
209-
const sanitizedOpts = {
210-
...src,
211-
-[...keysToExclude],
212-
...a,
213-
};
214-
```
215-
Desugared:
216-
```js
217-
const sanitizedOpts = (() => {
218-
const _$1 = {};
219-
for (const key in src) _$1[key] = src[key];
220-
for (const key of keysToExclude) delete _$1[key]; // Remove dynamic keys
221-
for (const key in a) _$1[key] = a[key];
222-
return _$1;
223-
})();
224-
```
225-
226-
#### 6. Using Complex Expressions
195+
#### 5. Using Complex Expressions
227196
Input:
228197
```js
229198
const sanitizedOpts = {
@@ -261,3 +230,27 @@ const sanitizedOpts = (() => {
261230
The proposed key exclusion syntax enhances the flexibility and clarity of object spread operations. Its ability to handle dynamic keys, complex expressions, strings with spaces, and symbols makes it a robust tool for JavaScript developers. By eliminating unnecessary object copies or deletions, it also provides performance benefits in large-scale applications.
262231

263232
Contributions and feedback are welcome!
233+
234+
## Graveyard
235+
236+
### Excluding Multiple Keys Dynamically
237+
You can exclude an array of keys using the spread operator within the exclusion syntax:
238+
239+
```js
240+
const sanitizedOpts = {
241+
...a,
242+
-[...keysToExclude], // Excludes all keys in the `keysToExclude` array
243+
...b,
244+
};
245+
```
246+
247+
Desugared:
248+
```js
249+
const sanitizedOpts = (() => {
250+
const _$1 = {};
251+
for (const key in src) _$1[key] = src[key];
252+
for (const key of keysToExclude) delete _$1[key]; // Remove dynamic keys
253+
for (const key in a) _$1[key] = a[key];
254+
return _$1;
255+
})();
256+
```

0 commit comments

Comments
 (0)