You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: ch02.asciidoc
+9-9
Original file line number
Diff line number
Diff line change
@@ -694,7 +694,7 @@ var car = {
694
694
name: 'Donald Draper'
695
695
},
696
696
brand: 'Peugeot',
697
-
make: 2015,
697
+
make: 2017,
698
698
model: '208',
699
699
preferences: {
700
700
airbags: true,
@@ -754,14 +754,14 @@ function splitDate(date) {
754
754
var rdate = /(\d+).(\d+).(\d+)/
755
755
return rdate.exec(date)
756
756
}
757
-
var [ , year, month, day] = splitDate('2015-11-06')
757
+
var [ , year, month, day] = splitDate('2017-11-06')
758
758
----
759
759
760
760
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.
761
761
762
762
[source,javascript]
763
763
----
764
-
var matches = splitDate('2015-11-06')
764
+
var matches = splitDate('2017-11-06')
765
765
if (matches === null) {
766
766
return
767
767
}
@@ -940,16 +940,16 @@ Another limitation of `.apply` is that combining it with the `new` keyword, when
940
940
941
941
[source,javascript]
942
942
----
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
945
945
----
946
946
947
947
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.
948
948
949
949
[source,javascript]
950
950
----
951
-
new Date(...[2015, 11, 31])
952
-
// <- Thu Dec 31 2015
951
+
new Date(...[2017, 11, 31])
952
+
// <- Thu Dec 31 2017
953
953
----
954
954
955
955
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
0 commit comments