Skip to content

Commit 9f40a84

Browse files
committedJun 16, 2017
Edited ch02.asciidoc with Atlas code editor
1 parent 292a023 commit 9f40a84

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
@@ -155,7 +155,7 @@ The last enhancement coming to object literals is ((("object literals", "compute
155155

156156
==== Method Definitions
157157

158-
Typically, ((("object literals", "method definitions", id="ol2md")))((("method definitions", id="mdef2")))you can declare methods on an object by adding properties to it. In the next snippet, we're creating an small event emitter that supports multiple kinds of events. It comes with an `emitter#on` method ((("emitter object", id="eo2")))that can be used to register event listeners, and an `emitter#emit` method that can be used to raise events:
158+
Typically, ((("object literals", "method definitions", id="ol2md")))((("method definitions", id="mdef2")))you can declare methods on an object by adding properties to it. In the next snippet, we're creating a small event emitter that supports multiple kinds of events. It comes with an `emitter#on` method ((("emitter object", id="eo2")))that can be used to register event listeners, and an `emitter#emit` method that can be used to raise events:
159159

160160
[source,javascript]
161161
----
@@ -178,7 +178,7 @@ var emitter = {
178178
}
179179
----
180180

181-
Starting in ES6, you can declare methods on an object literal using the new method definition syntax. In this case, we can omit the colon and the `function` keyword. This is meant as a terse alternative to traditional method declarations where you need to use the `function` ((("function keyword")))keyword. The following example shows how our `emitter` object looks like when using method definitions.
181+
Starting in ES6, you can declare methods on an object literal using the new method definition syntax. In this case, we can omit the colon and the `function` keyword. This is meant as a terse alternative to traditional method declarations where you need to use the `function` ((("function keyword")))keyword. The following example shows how our `emitter` object looks when using method definitions.
182182

183183
[source,javascript]
184184
----
@@ -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")))((("anonymous functions")))anonymous functions, by omitting the name when assigning the function to a variable, a property, or a function call.
219219

220220
[source,javascript]
221221
----
@@ -224,7 +224,7 @@ var example = function (parameters) {
224224
}
225225
----
226226

227-
Starting with ES6, you can use arrow functions as another way of writing anonymous functions. Keep in mind, there's several slightly different ways of writing them. The following piece of code shows an arrow function that's very similar to the anonymous function we just saw. The only difference seems to be the missing `function` keyword and the `=>` arrow to the right of the parameter list.
227+
Starting with ES6, you can use arrow functions as another way of writing anonymous functions. Keep in mind, there are several slightly different ways of writing them. The following piece of code shows an arrow function that's very similar to the anonymous function we just saw. The only difference seems to be the missing `function` keyword and the `=>` arrow to the right of the parameter list.
228228

229229
[source,javascript]
230230
----
@@ -382,7 +382,7 @@ throwError('this is a warning')
382382
at throwError
383383
----
384384

385-
Arrow functions are neat when it comes to defining anonymous functions that should probably be lexically bound anyway, and they can definitely make your code more terse in some situations. They are particularly useful in most functional programming situations such as when using `.map`, `.filter`, or `.reduce` on collections, as shown in the following example:
385+
Arrow functions are neat when it comes to defining anonymous functions that should probably be lexically bound anyway, and they can definitely make your code more terse in some situations. They are particularly useful in most functional programming situations, such as when using `.map`, `.filter`, or `.reduce` on collections, as shown in the following example:
386386

387387
[source,javascript]
388388
----
@@ -444,7 +444,7 @@ In a similar fashion, you could mix and match destructuring with regular variabl
444444
var { pseudonym } = character, two = 2
445445
----
446446

447-
If you want to extract a property named `pseudonym` but would like to declare it as a variable named `alias`, you can use the following destructuring syntax known as aliasing. Note that you can use `alias` or any other valid variable name:
447+
If you want to extract a property named `pseudonym` but would like to declare it as a variable named `alias`, you can use the following destructuring syntax, known as _aliasing_. Note that you can use `alias` or any other valid variable name:
448448

449449
[source,javascript]
450450
----
@@ -453,7 +453,7 @@ console.log(alias)
453453
// <- 'Batman'
454454
----
455455

456-
While aliases don't look any simpler than the ES5 flavor, `alias = character.pseudonym`, ((("aliases", id="al2")))they start making sense when you consider the fact that destructuring supports deep structures as in the following example:
456+
While aliases don't look any simpler than the ES5 flavor, `alias = character.pseudonym`, ((("aliases", id="al2")))they start making sense when you consider the fact that destructuring supports deep structures, as in the following example:
457457

458458
[source,javascript]
459459
----
@@ -469,7 +469,7 @@ var { metadata: { gender: characterGender } } = character
469469

470470
The scenario we just saw repeats itself frequently, because properties are often named in the context of their host object. While `palette.color.code` is perfectly descriptive, `code` on its own could mean a wide variety of things, and aliases such as `colorCode` can help you bring context back into the variable name while still using destructuring.
471471

472-
Whenever you access an nonexistent property in ES5 notation, you get a value of `undefined`:
472+
Whenever you access a nonexistent property in ES5 notation, you get a value of `undefined`:
473473

474474
[source,javascript]
475475
----
@@ -746,7 +746,7 @@ console.log(random({ max: 24 }))
746746
// <- 18
747747
----
748748

749-
Regular ((("assignment destructuring", "function parameters", startref="ad2fpd")))((("destructuring", "function parameters", startref="d2fpd")))((("function parameters", startref="fpd2")))expressions are another great fit for destructuring. Destructuring empowers you to name groups from a match without having to resort to index numbers. Here's an example `RegExp` that could be used for parsing simple dates, and an example of destructuring those dates into each of its components. The first entry in the resulting array is reserved for the raw input string, and we can discard it.
749+
Regular ((("assignment destructuring", "function parameters", startref="ad2fpd")))((("destructuring", "function parameters", startref="d2fpd")))((("function parameters", startref="fpd2")))expressions are another great fit for destructuring. Destructuring empowers you to name groups from a match without having to resort to index numbers. Here's an example `RegExp` that could be used for parsing simple dates, and an example of destructuring those dates into each of their components. The first entry in the resulting array is reserved for the raw input string, and we can discard it.
750750

751751
[source,javascript]
752752
----

0 commit comments

Comments
 (0)
Please sign in to comment.