Skip to content

Commit 5872aca

Browse files
committed
Simplify websocket destructuring example
Instead of extracting values and destructuring them positionally, we can destructure by key, which is both shorter and clearer about what's going on.
1 parent adf1f07 commit 5872aca

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/content/docs/workers/runtime-apis/websockets.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ let websocketPair = new WebSocketPair();
2727

2828
The WebSocketPair returned from this constructor is an Object, with two WebSockets at keys `0` and `1`.
2929

30-
These WebSockets are commonly referred to as `client` and `server`. The below example combines `Object.values` and ES6 destructuring to retrieve the WebSockets as `client` and `server`:
30+
These WebSockets are commonly referred to as `client` and `server`. The below example uses ES6 destructuring to retrieve the WebSockets as `client` and `server`:
3131

3232
```js
33-
let [client, server] = Object.values(new WebSocketPair());
33+
let {0: client, 1: server} = new WebSocketPair();
3434
```
3535

3636
## Methods

0 commit comments

Comments
 (0)