Skip to content

Commit ea390f4

Browse files
author
wendy@lastlookeditorial.com
committed
Edited ch02.asciidoc with Atlas code editor
1 parent bdfef23 commit ea390f4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

ch02.asciidoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ function name(parameters) {
215215
}
216216
----
217217

218-
You could also create ((("arrow functions", "anonymous")))((("anonymous functions")))anonymous functions, by omitting the name when assigning the function to a variable, a property, or a function call.
218+
You could also create ((("arrow functions", "anonymous", id="af2a")))((("anonymous functions", id="af2")))anonymous functions, by omitting the name when assigning the function to a variable, a property, or a function call.
219219

220220
[source,javascript]
221221
----
@@ -258,7 +258,7 @@ setTimeout(function () {
258258
// <- 3
259259
----
260260

261-
If we had defined the function passed to `setInterval` as a regular anonymous function instead of using an arrow function, `this` would've been bound to the context of the ((("arrow functions", "anonymous")))((("anonymous functions")))anonymous function, instead of the context of the `start` method. We could have implemented `timer` with a declaration like `var self = this` at the beginning of the `start` method, and then referencing `self` instead of `this`. With arrow functions, the added complexity of keeping context references around fades away and we can focus on the functionality of our code.
261+
If we had defined the function passed to `setInterval` as a regular anonymous function instead of using an arrow function, `this` would've been bound to the context of the ((("arrow functions", "anonymous", startref="af2a")))((("anonymous functions", startref="af2")))anonymous function, instead of the context of the `start` method. We could have implemented `timer` with a declaration like `var self = this` at the beginning of the `start` method, and then referencing `self` instead of `this`. With arrow functions, the added complexity of keeping context references around fades away and we can focus on the functionality of our code.
262262

263263
In a similar fashion, lexical binding in ES6 arrow functions also means that function calls won't be able to change the `this` context when using `.call`, `.apply`, `.bind`, etc. That limitation is usually more useful than not, as it ensures that the context will always be preserved and constant.
264264

0 commit comments

Comments
 (0)