commit
42ca672a5e
1 changed files with 14 additions and 14 deletions
|
@ -136,7 +136,7 @@ alert(rest.length); // 2
|
|||
*/!*
|
||||
```
|
||||
|
||||
The value of `rest` is the array of the remaining array elements. We can use any other variable name in place of `rest`, just make sure it has three dots before it and goes last in the destructuring assignmemnt.
|
||||
The value of `rest` is the array of the remaining array elements. We can use any other variable name in place of `rest`, just make sure it has three dots before it and goes last in the destructuring assignment.
|
||||
|
||||
### Default values
|
||||
|
||||
|
@ -434,7 +434,7 @@ let options = {
|
|||
function showMenu(*!*{title = "Untitled", width = 200, height = 100, items = []}*/!*) {
|
||||
// title, items – taken from options,
|
||||
// width, height – defaults used
|
||||
alert( title + ' ' + width + ' ' + height ); // My Menu 100 200
|
||||
alert( `${title} ${width} ${height}` ); // My Menu 200 100
|
||||
alert( items ); // Item1, Item2
|
||||
}
|
||||
|
||||
|
@ -457,7 +457,7 @@ function showMenu({
|
|||
items: [item1, item2] // items first element goes to item1, second to item2
|
||||
}) {
|
||||
*/!*
|
||||
alert( title + ' ' + w + ' ' + h ); // My Menu 100 200
|
||||
alert( `${title} ${w} ${h}` ); // My Menu 100 200
|
||||
alert( item1 ); // Item1
|
||||
alert( item2 ); // Item2
|
||||
}
|
||||
|
@ -488,7 +488,7 @@ We can fix this by making `{}` the default value for the whole destructuring thi
|
|||
```js run
|
||||
// simplified parameters a bit for clarity
|
||||
function showMenu(*!*{ title = "Menu", width = 100, height = 200 } = {}*/!*) {
|
||||
alert( title + ' ' + width + ' ' + height );
|
||||
alert( `${title} ${width} ${height}` );
|
||||
}
|
||||
|
||||
showMenu(); // Menu 100 200
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue