@@ -16,7 +16,7 @@ quote}}
1616
1717[ Chapter ?] ( data ) introduced JavaScript's ((object))s. In programming
1818culture, we have a thing called _ ((object-oriented programming))_ , a
19- set of techniques that uses objects (and related concepts) as the
19+ set of techniques that use objects (and related concepts) as the
2020central principle of program organization.
2121
2222Though no one really agrees on its precise definition, object-oriented
@@ -297,7 +297,7 @@ function, and returned at the end of the function.
297297
298298{{index "prototype property"}}
299299
300- The appropriate prototype object for a constructor is found by taking
300+ The prototype object used when constructing objects is found by taking
301301the ` prototype ` property of the constructor function.
302302
303303{{index "rabbit example"}}
@@ -336,6 +336,15 @@ is `Function.prototype`, since constructors are functions. Its
336336` prototype ` _ property_ holds the prototype used for instances created
337337through it.
338338
339+ ```
340+ console.log(Object.getPrototypeOf(Rabbit) ==
341+ Function.prototype);
342+ // → true
343+ console.log(Object.getPrototypeOf(weirdRabbit) ==
344+ Rabbit.prototype);
345+ // → true
346+ ```
347+
339348## Class notation
340349
341350So JavaScript ((class))es are ((constructor)) functions with a
@@ -370,10 +379,11 @@ constructor definition from the previous section. It just looks nicer.
370379
371380{{index [ "class declaration", properties] }}
372381
373- Class declarations only allow _ methods_ —properties that hold
382+ Class declarations currently only allow _ methods_ —properties that hold
374383functions—to be added to the ((prototype)). This can be somewhat
375- inconvenient when you want to save a non-function value in there. You
376- can still create such properties by directly manipulating the
384+ inconvenient when you want to save a non-function value in there.
385+ The next version of the language will probably improve this. For now, you
386+ can create such properties by directly manipulating the
377387prototype after you've defined the class.
378388
379389Like ` function ` , ` class ` can be used both in statement and in
@@ -392,9 +402,9 @@ console.log(object.getWord());
392402{{index "shared property", overriding}}
393403
394404When you add a ((property)) to an object, whether it is present in the
395- prototype or not, the property is added to the object _ itself_ , which
396- will henceforth have it as its own property. If there _ is _ a property
397- by the same name in the prototype, this property will no longer affect
405+ prototype or not, the property is added to the object _ itself_ .
406+ If there was already a property with
407+ the same name in the prototype, this property will no longer affect
398408the object, as it is now hidden behind the object's own property.
399409
400410```
@@ -524,6 +534,8 @@ console.log(`Júlia is ${ages.get("Júlia")}`);
524534// → Júlia is 62
525535console.log("Is Jack's age known?", ages.has("Jack"));
526536// → Is Jack's age known? false
537+ console.log(ages.has("toString"));
538+ // → false
527539```
528540
529541{{index interface, "set method", "get method", "has method", encapsulation}}
@@ -669,8 +681,8 @@ When called, that method should return an object that provides a
669681second interface, _ iterator_ . This is the actual thing that iterates.
670682It has a ` next ` method that returns the next result. That result
671683should be an object with a ` value ` property, providing the next value,
672- and a ` done ` property, which should be true when there are no more
673- results and false otherwise.
684+ if there is one, and a ` done ` property which should be true when there
685+ are no more results and false otherwise.
674686
675687Note that the ` next ` , ` value ` , and ` done ` property names are plain
676688strings, not symbols. Only ` Symbol.iterator ` , which is likely to be
@@ -697,14 +709,14 @@ class, acting as a two-dimensional array.
697709
698710``` {includeCode: true}
699711class Matrix {
700- constructor(width, height, content = (x, y) => undefined) {
712+ constructor(width, height, element = (x, y) => undefined) {
701713 this.width = width;
702714 this.height = height;
703715 this.content = [];
704716
705717 for (let y = 0; y < height; y++) {
706718 for (let x = 0; x < width; x++) {
707- this.content[y * width + x] = content (x, y);
719+ this.content[y * width + x] = element (x, y);
708720 }
709721 }
710722 }
@@ -895,10 +907,10 @@ the old class.
895907
896908``` {includeCode: "top_lines: 17"}
897909class SymmetricMatrix extends Matrix {
898- constructor(size, content = (x, y) => undefined) {
910+ constructor(size, element = (x, y) => undefined) {
899911 super(size, size, (x, y) => {
900- if (x < y) return content (y, x);
901- else return content (x, y);
912+ if (x < y) return element (y, x);
913+ else return element (x, y);
902914 });
903915 }
904916
@@ -916,7 +928,7 @@ console.log(matrix.get(2, 3));
916928```
917929
918930The use of the word ` extends ` indicates that this class shouldn't be
919- based on the default ` Object ` prototype, but on some other class. This
931+ directly based on the default ` Object ` prototype, but on some other class. This
920932is called the _ ((superclass))_ . The derived class is the
921933_ ((subclass))_ .
922934
0 commit comments