@@ -27,7 +27,7 @@ can be applied in JavaScript.
2727{{index encapsulation, isolation, modularity}}
2828
2929The 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
3131own state.
3232
3333This way, some knowledge about the way a piece of the program works
@@ -47,13 +47,13 @@ implementation.
4747
4848Such program pieces are modeled using ((object))s. Their interface
4949consists 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
5151outside code should not be touching, are called _ private_ .
5252
5353{{index "underscore character"}}
5454
5555Many 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
5757ones altogether. JavaScript, once again taking the minimalist
5858approach, does not. Not yet, at least—there is work underway to add
5959this to the language.
@@ -115,7 +115,7 @@ hungryRabbit.speak("I could use a carrot right now.");
115115You can think of ` this ` as an extra ((parameter)) that is passed in a
116116different way. If you want to pass it explicitly, you can use a
117117function'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```
121121speak.call(hungryRabbit, "Burp!");
@@ -129,9 +129,9 @@ scope in a regular function defined with the `function` keyword.
129129{{index this, "arrow function"}}
130130
131131Arrow 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
133133something like the following code, which references ` this ` from inside
134- a local function.
134+ a local function:
135135
136136```
137137function 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
207207Many 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
209209default properties. Functions derive from ` Function.prototype ` , and
210210arrays derive from ` Array.prototype ` .
211211
@@ -330,7 +330,7 @@ It is important to understand the distinction between the way a
330330prototype is associated with a constructor (through its ` prototype `
331331property) and the way objects _ have_ a prototype (which can be found
332332with ` 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
335335through it.
336336
@@ -422,12 +422,12 @@ itself can be looked up.
422422Overriding properties that exist in a prototype can be a useful thing
423423to do. As the rabbit teeth example shows, it can be used to express
424424exceptional 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
426426standard 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
431431different ` 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.
445445Directly calling ` Object.prototype.toString ` with an array produces a
446446different 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
448448brackets.
449449
450450```
@@ -485,9 +485,9 @@ toString in our map. Yet, because plain objects derive from
485485{{index "Object.create function", prototype}}
486486
487487As 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
489489objects 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
491491safely be used as a map.
492492
493493```
@@ -502,7 +502,7 @@ use an object as your map.
502502{{index "Map class"}}
503503
504504Fortunately, 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
506506type of keys.
507507
508508```
@@ -583,7 +583,7 @@ to know what symbols are.
583583## Symbols
584584
585585It 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
587587the ` toString ` method is supposed to convert the object into a piece
588588of yarn. It would not be possible for an object to conform to both
589589that interface and the standard use of ` toString ` .
@@ -710,7 +710,7 @@ class Matrix {
710710```
711711
712712The 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
714714element in the fifth row is (using zero-based indexing) stored at
715715position 4 × _ width_ + 2.
716716
@@ -752,7 +752,7 @@ class MatrixIterator {
752752The class tracks the progress of iterating over a matrix in its ` x `
753753and ` y ` properties. The ` next ` method starts by checking whether the
754754bottom 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
756756position, moving to the next row if necessary.
757757
758758Let us set up the ` Matrix ` class to be iterable. Throughout this book,
@@ -790,7 +790,7 @@ for (let {x, y, value} of matrix) {
790790Interfaces often consist mostly of methods, but it is also okay to
791791include properties that hold non-function values. For example, ` Map `
792792objects have a ` size ` property that tells you how many keys are stored
793- in it .
793+ in them .
794794
795795It is not even necessary for such an object to compute and store such
796796a property directly in the instance. Even properties that are accessed
@@ -851,7 +851,7 @@ in the `fahrenheit` getter and setter.
851851
852852Sometimes you want to attach some properties directly to your
853853constructor 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
855855provide additional ways to create instances.
856856
857857Inside 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
866866Some 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
868868same. In other words, the value stored at _ x_ ,_ y_ is always the same
869869as 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
872872the fact that the matrix is and remains symmetrical. We could write it
873873from scratch, but that would involve repeating some code very similar
874874to what we already wrote.
@@ -878,7 +878,7 @@ to what we already wrote.
878878JavaScript's prototype system makes it possible to create a _ new_
879879class, much like the old class, but with new definitions for some of
880880its 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
883883In object-oriented programming terms, this is called
884884_ ((inheritance))_ . The new class inherits properties and behavior from
@@ -921,7 +921,7 @@ diagonal.
921921
922922The ` set ` method again uses ` super ` , but this time not to call the
923923constructor, 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
925925behavior. Because ` this.set ` refers to the _ new_ ` set ` method, calling
926926that wouldn't work. Inside class methods, ` super ` provides a way to
927927call 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 `
970970is an instance of ` Matrix ` . The operator can also be applied to
971971standard constructors like ` Array ` . Almost every object is an instance
972972of ` Object ` .
@@ -1004,7 +1004,7 @@ different objects that provide the interface. This is called
10041004_ polymorphism_ .
10051005
10061006When 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
10081008existing 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
11421142The ` 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
11441144group.
11451145
11461146hint}}
@@ -1157,7 +1157,7 @@ you aren't clear on the exact form of the interface anymore.
11571157
11581158If you used an array to represent the group's members, don't just
11591159return 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
11621162It is okay if your iterator behaves strangely when the group is
11631163modified during iteration.
@@ -1187,7 +1187,7 @@ position in the group. Every time `next` is called, it checks whether
11871187it is done, and if not, moves past the current value and returns it.
11881188
11891189The ` 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
11911191that group.
11921192
11931193hint}}
0 commit comments