Skip to content

Commit babf801

Browse files
committed
remove ${...} from destructuring
1 parent d7e4ea7 commit babf801

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

1-js/10-es-modern/3-destructuring/article.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ let options = {
132132
let {title, width, height} = options;
133133
*/!*
134134

135-
alert(`${title} ${width} ${height}`); // Меню 100 200
135+
alert(title); // Меню
136+
alert(width); // 100
137+
alert(height); // 200
136138
```
137139

138140
Как видно, свойства `options.title`, `options.width` и `options.height` автоматически присвоились соответствующим переменным.
@@ -153,7 +155,9 @@ let options = {
153155
let {width: w, height: h, title} = options;
154156
*/!*
155157

156-
alert(`${title} ${w} ${h}`); // Меню 100 200
158+
alert(title); // Меню
159+
alert(w); // 100
160+
alert(h); // 200
157161
```
158162

159163
В примере выше свойство `width` отправилось в переменную `w`, свойство `height` -- в переменную `h`, а `title` -- в переменную с тем же названием.
@@ -172,7 +176,9 @@ let options = {
172176
let {width=100, height=200, title} = options;
173177
*/!*
174178

175-
alert(`${title} ${width} ${height}`); // Меню 100 200
179+
alert(title); // Меню
180+
alert(width); // 100
181+
alert(height); // 200
176182
```
177183

178184
Можно и сочетать одновременно двоеточие и равенство:
@@ -190,7 +196,9 @@ let options = {
190196
let {width:w=100, height:h=200, title} = options;
191197
*/!*
192198

193-
alert(`${title} ${w} ${h}`); // Меню 100 200
199+
alert(title); // Меню
200+
alert(w); // 100
201+
alert(h); // 200
194202
```
195203

196204
А что, если в объекте больше значений, чем переменных? Можно ли куда-то присвоить "остаток", аналогично массивам?
@@ -275,7 +283,11 @@ let options = {
275283
let { title="Меню", size: {width, height}, items: [item1, item2] } = options;
276284

277285
// Меню 100 200 Пончик Пирожное
278-
alert(`${title} ${width} ${height} ${item1} ${item2}`);
286+
alert(title); // Меню
287+
alert(width); // 100
288+
alert(height); // 200
289+
alert(item1); // Пончик
290+
alert(item2); // Пирожное
279291
```
280292

281293
Как видно, весь объект `options` корректно разбит на переменные.

0 commit comments

Comments
 (0)