Skip to content

Commit b3da218

Browse files
committed
minor tweaks
1 parent 3b4e9f0 commit b3da218

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

ch02.asciidoc

+9-9
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ var car = {
694694
name: 'Donald Draper'
695695
},
696696
brand: 'Peugeot',
697-
make: 2015,
697+
make: 2017,
698698
model: '208',
699699
preferences: {
700700
airbags: true,
@@ -754,14 +754,14 @@ function splitDate(date) {
754754
var rdate = /(\d+).(\d+).(\d+)/
755755
return rdate.exec(date)
756756
}
757-
var [ , year, month, day] = splitDate('2015-11-06')
757+
var [ , year, month, day] = splitDate('2017-11-06')
758758
----
759759

760760
You'll want to be careful when the regular expression doesn't match, as that returns `null`. Perhaps a better approach would be to test for the failure case before destructuring, as shown in the following bit of code.
761761

762762
[source,javascript]
763763
----
764-
var matches = splitDate('2015-11-06')
764+
var matches = splitDate('2017-11-06')
765765
if (matches === null) {
766766
return
767767
}
@@ -940,16 +940,16 @@ Another limitation of `.apply` is that combining it with the `new` keyword, when
940940

941941
[source,javascript]
942942
----
943-
new (Date.bind.apply(Date, [null, 2015, 11, 31]))
944-
// <- Thu Dec 31 2015
943+
new (Date.bind.apply(Date, [null, 2017, 11, 31]))
944+
// <- Thu Dec 31 2017
945945
----
946946

947947
As shown in the next snippet, the spread operator strips away all the complexity and we're only left with the important bits. It's a `new` instance, it uses `...` to spread a dynamic list of arguments over the function call, and it's a `Date`. ((("Date()")))That's it.
948948

949949
[source,javascript]
950950
----
951-
new Date(...[2015, 11, 31])
952-
// <- Thu Dec 31 2015
951+
new Date(...[2017, 11, 31])
952+
// <- Thu Dec 31 2017
953953
----
954954

955955
The following table summarizes the use cases we've discussed for the spread operator.
@@ -960,7 +960,7 @@ The following table summarizes the use cases we've discussed for the spread oper
960960
|Concatenation|`[1, 2].concat(more)`|`[1, 2, ...more]`
961961
|Push an array onto list|`list.push.apply(list, items)`|`list.push(...items)`
962962
|Destructuring|`a = list[0], other = list.slice(1)` | `[a, ...other] = list`
963-
|`new` and `apply`|`new (Date.bind.apply(Date, [null,2015,31,8]))`| `new Date(...[2015,31,8])`
963+
|`new` and `apply`|`new (Date.bind.apply(Date, [null,2017,11,31]))`| `new Date(...[2017,11,31])`
964964
|=======
965965

966966
[[template_literals]]
@@ -1001,7 +1001,7 @@ It will be up to your coding style guides to decide how much logic you want to c
10011001
[source,javascript]
10021002
----
10031003
`The time and date is ${ new Date().toLocaleString() }.`
1004-
// <- 'the time and date is 8/26/2015, 3:15:20 PM'
1004+
// <- 'the time and date is 8/26/2017, 3:15:20 PM'
10051005
----
10061006

10071007
You could interpolate mathematical operations.

0 commit comments

Comments
 (0)