Array destructuring instead of Object destructuring with rename
When you want to create a couple promises you need to write a lot of boilerplate using destructuring with rename:
```js
const {promise, resolve, reject} = Promise.withResolvers();
const {
promise: readFile,
resolve: resolveReadFile,
reject: rejectReadFile
} = Promise.withResolvers();
```
Would be great to have ability to use array destructuring instead:
```js
const [promise, resolve, reject] = Promise.withResolvers();
const [readFile, resolveReadFile, rejectReadFile] = Promise.withResolvers();
```
In a similar to [`Object.entries()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries) and [`Array.prototype.entries()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries).
Where code looks like this:
```js
for (const [index, promise] of promises.entries())
log(i, promise);
```
It’s much shorter and simpler in a long running distance.
关闭于 2023-07-11 15 条评论