Skip to content

Commit 4ee19d9

Browse files
committed
Integrate editing for Chapter 6
1 parent ba3a7fa commit 4ee19d9

1 file changed

Lines changed: 28 additions & 28 deletions

File tree

06_object.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ can be applied in JavaScript.
2727
{{index encapsulation, isolation, modularity}}
2828

2929
The core idea in object-oriented programming is to divide programs
30-
into smaller pieces, and make each piece responsible for managing its
30+
into smaller pieces and make each piece responsible for managing its
3131
own state.
3232

3333
This way, some knowledge about the way a piece of the program works
@@ -47,13 +47,13 @@ implementation.
4747

4848
Such program pieces are modeled using ((object))s. Their interface
4949
consists of a specific set of ((method))s and properties. Properties
50-
that are part of the interface are called _public_. The others, that
50+
that are part of the interface are called _public_. The others, which
5151
outside code should not be touching, are called _private_.
5252

5353
{{index "underscore character"}}
5454

5555
Many languages provide a way to distinguish public and private
56-
properties, and will prevent outside code from accessing the private
56+
properties and will prevent outside code from accessing the private
5757
ones altogether. JavaScript, once again taking the minimalist
5858
approach, does not. Not yet, at least—there is work underway to add
5959
this to the language.
@@ -115,7 +115,7 @@ hungryRabbit.speak("I could use a carrot right now.");
115115
You can think of `this` as an extra ((parameter)) that is passed in a
116116
different way. If you want to pass it explicitly, you can use a
117117
function's `call` method, which takes the `this` value as first
118-
argument, and treats further arguments as normal parameters.
118+
argument and treats further arguments as normal parameters.
119119

120120
```
121121
speak.call(hungryRabbit, "Burp!");
@@ -129,9 +129,9 @@ scope in a regular function defined with the `function` keyword.
129129
{{index this, "arrow function"}}
130130

131131
Arrow functions are different—they do not bind their own `this`, but
132-
can see the `this` binding of the scope around them. Thus you can do
132+
can see the `this` binding of the scope around them. Thus, you can do
133133
something like the following code, which references `this` from inside
134-
a local function.
134+
a local function:
135135

136136
```
137137
function normalize() {
@@ -205,7 +205,7 @@ It provides a few ((method))s that show up in all objects, such as
205205
{{index inheritance, "Function prototype", "Array prototype", "Object prototype"}}
206206

207207
Many objects don't directly have `Object.prototype` as their
208-
((prototype)), but instead have another object, which provides its own
208+
((prototype)), but instead have another object that provides a different set of
209209
default properties. Functions derive from `Function.prototype`, and
210210
arrays derive from `Array.prototype`.
211211

@@ -330,7 +330,7 @@ It is important to understand the distinction between the way a
330330
prototype is associated with a constructor (through its `prototype`
331331
property) and the way objects _have_ a prototype (which can be found
332332
with `Object.getPrototypeOf`). The actual prototype of a constructor
333-
is `Function.prototype` since constructors are functions. Its
333+
is `Function.prototype`, since constructors are functions. Its
334334
`prototype` _property_ holds the prototype used for instances created
335335
through it.
336336

@@ -422,12 +422,12 @@ itself can be looked up.
422422
Overriding properties that exist in a prototype can be a useful thing
423423
to do. As the rabbit teeth example shows, it can be used to express
424424
exceptional properties in instances of a more generic class of
425-
objects, while letting the nonexceptional objects simply take a
425+
objects, while letting the nonexceptional objects take a
426426
standard value from their prototype.
427427

428428
{{index "toString method", "Array prototype", "Function prototype"}}
429429

430-
It is also used to give the standard function and array prototypes a
430+
Overriding is also used to give the standard function and array prototypes a
431431
different `toString` method than the basic object prototype.
432432

433433
```
@@ -444,7 +444,7 @@ Calling `toString` on an array gives a result similar to calling
444444
`.join(",")` on it—it puts commas between the values in the array.
445445
Directly calling `Object.prototype.toString` with an array produces a
446446
different string. That function doesn't know about arrays, so it
447-
simply puts the word "object" and the name of the type between square
447+
simply puts the word _object_ and the name of the type between square
448448
brackets.
449449

450450
```
@@ -485,9 +485,9 @@ toString in our map. Yet, because plain objects derive from
485485
{{index "Object.create function", prototype}}
486486

487487
As such, using plain objects as maps is dangerous. There are several
488-
possible ways to avoid this problem. Firstly, it is possible to create
488+
possible ways to avoid this problem. First, it is possible to create
489489
objects with _no_ prototype. If you pass `null` to `Object.create`,
490-
the resulting object will not derive from `Object.prototype`, and can
490+
the resulting object will not derive from `Object.prototype` and can
491491
safely be used as a map.
492492

493493
```
@@ -502,7 +502,7 @@ use an object as your map.
502502
{{index "Map class"}}
503503

504504
Fortunately, JavaScript comes with a class called `Map` that is
505-
written for this exact purpose. It stores a mapping, and allows any
505+
written for this exact purpose. It stores a mapping and allows any
506506
type of keys.
507507

508508
```
@@ -583,7 +583,7 @@ to know what symbols are.
583583
## Symbols
584584

585585
It is possible for multiple interfaces to use the same property name
586-
for different things. For example I could define an interface in which
586+
for different things. For example, I could define an interface in which
587587
the `toString` method is supposed to convert the object into a piece
588588
of yarn. It would not be possible for an object to conform to both
589589
that interface and the standard use of `toString`.
@@ -710,7 +710,7 @@ class Matrix {
710710
```
711711

712712
The class stores its content in a single array of _width_ × _height_
713-
elements. The elements are stored row-by-row, so for example the third
713+
elements. The elements are stored row-by-row, so, for example, the third
714714
element in the fifth row is (using zero-based indexing) stored at
715715
position 4 × _width_ + 2.
716716

@@ -752,7 +752,7 @@ class MatrixIterator {
752752
The class tracks the progress of iterating over a matrix in its `x`
753753
and `y` properties. The `next` method starts by checking whether the
754754
bottom of the matrix has been reached. If it hasn't, it _first_
755-
creates the object holding the current value, and _then_ updates its
755+
creates the object holding the current value and _then_ updates its
756756
position, moving to the next row if necessary.
757757

758758
Let us set up the `Matrix` class to be iterable. Throughout this book,
@@ -790,7 +790,7 @@ for (let {x, y, value} of matrix) {
790790
Interfaces often consist mostly of methods, but it is also okay to
791791
include properties that hold non-function values. For example, `Map`
792792
objects have a `size` property that tells you how many keys are stored
793-
in it.
793+
in them.
794794

795795
It is not even necessary for such an object to compute and store such
796796
a property directly in the instance. Even properties that are accessed
@@ -851,7 +851,7 @@ in the `fahrenheit` getter and setter.
851851

852852
Sometimes you want to attach some properties directly to your
853853
constructor function, rather than to the prototype. Such methods won't
854-
have access to a class instance, but can for example be used to
854+
have access to a class instance but can, for example, be used to
855855
provide additional ways to create instances.
856856

857857
Inside a class declaration, methods that have `static` written before
@@ -864,11 +864,11 @@ temperature using degrees Fahrenheit.
864864
{{index inheritance, "matrix example", "object-oriented programming", "SymmetricMatrix class"}}
865865

866866
Some matrices are known to be _symmetric_. If you mirror a symmetric
867-
matrix around its top-left to bottom-right diagonal, it stays the
867+
matrix around its top-left-to-bottom-right diagonal, it stays the
868868
same. In other words, the value stored at _x_,_y_ is always the same
869869
as that at _y_,_x_.
870870

871-
Imagine we need a data structure like `Matrix`, but one which enforces
871+
Imagine we need a data structure like `Matrix` but one that enforces
872872
the fact that the matrix is and remains symmetrical. We could write it
873873
from scratch, but that would involve repeating some code very similar
874874
to what we already wrote.
@@ -878,7 +878,7 @@ to what we already wrote.
878878
JavaScript's prototype system makes it possible to create a _new_
879879
class, much like the old class, but with new definitions for some of
880880
its properties. The prototype for the new class derives from the old
881-
prototype, but adds a new definition for, say, the `set` method.
881+
prototype but adds a new definition for, say, the `set` method.
882882

883883
In object-oriented programming terms, this is called
884884
_((inheritance))_. The new class inherits properties and behavior from
@@ -921,7 +921,7 @@ diagonal.
921921

922922
The `set` method again uses `super`, but this time not to call the
923923
constructor, but to call a specific method from the superclass' set of
924-
methods. We are redefining `set`, but do want to use the original
924+
methods. We are redefining `set` but do want to use the original
925925
behavior. Because `this.set` refers to the _new_ `set` method, calling
926926
that wouldn't work. Inside class methods, `super` provides a way to
927927
call methods as they were defined in the superclass.
@@ -966,7 +966,7 @@ console.log([1] instanceof Array);
966966

967967
{{index inheritance}}
968968

969-
The operator will see through inherited types so a `SymmetricMatrix`
969+
The operator will see through inherited types, so a `SymmetricMatrix`
970970
is an instance of `Matrix`. The operator can also be applied to
971971
standard constructors like `Array`. Almost every object is an instance
972972
of `Object`.
@@ -1004,7 +1004,7 @@ different objects that provide the interface. This is called
10041004
_polymorphism_.
10051005

10061006
When implementing multiple classes that differ in only some details,
1007-
it can be helpful to write the new classes as _subclass_ of an
1007+
it can be helpful to write the new classes as _subclasses_ of an
10081008
existing class, _inheriting_ part of its behavior.
10091009

10101010
## Exercises
@@ -1140,7 +1140,7 @@ members with the newly filtered version of the array.
11401140
{{index "for/of loop", "iterable interface"}}
11411141

11421142
The `from` method can use a `for`/`of` loop to get the values out of
1143-
the iterable object, and call `add` to put them into a newly created
1143+
the iterable object and call `add` to put them into a newly created
11441144
group.
11451145

11461146
hint}}
@@ -1157,7 +1157,7 @@ you aren't clear on the exact form of the interface anymore.
11571157

11581158
If you used an array to represent the group's members, don't just
11591159
return the iterator created by calling the `Symbol.iterator` method on
1160-
the array. That would work, but defeats the purpose of this exercise.
1160+
the array. That would work, but it defeats the purpose of this exercise.
11611161

11621162
It is okay if your iterator behaves strangely when the group is
11631163
modified during iteration.
@@ -1187,7 +1187,7 @@ position in the group. Every time `next` is called, it checks whether
11871187
it is done, and if not, moves past the current value and returns it.
11881188

11891189
The `Group` class itself gets a method named by `Symbol.iterator`
1190-
which, when called, returns a new instance of the iterator class for
1190+
that, when called, returns a new instance of the iterator class for
11911191
that group.
11921192

11931193
hint}}

0 commit comments

Comments
 (0)