Skip to content

Commit 83683be

Browse files
authored
Merge pull request #257 from odsantos/update-prototype-inheritance
Update prototype inheritance folder
2 parents 874b88e + 210496e commit 83683be

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

1-js/08-prototypes/01-prototype-inheritance/3-proto-and-this/solution.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
That's because `this` is an object before the dot, so `rabbit.eat()` modifies `rabbit`.
44

55
Property lookup and execution are two different things.
6-
The method `rabbit.eat` is first found in the prototype, then executed with `this=rabbit`
6+
7+
The method `rabbit.eat` is first found in the prototype, then executed with `this=rabbit`.

1-js/08-prototypes/01-prototype-inheritance/4-hamster-proto/solution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Let's look carefully at what's going on in the call `speedy.eat("apple")`.
1010

1111
So all hamsters share a single stomach!
1212

13-
Every time the `stomach` is taken from the prototype, then `stomach.push` modifies it "at place".
13+
Both for `lazy.stomach.push(...)` and `speedy.stomach.push()`, the property `stomach` is found in the prototype (as it's not in the object itself), then the new data is pushed into it.
1414

1515
Please note that such thing doesn't happen in case of a simple assignment `this.stomach=`:
1616

@@ -77,4 +77,4 @@ alert( speedy.stomach ); // apple
7777
alert( lazy.stomach ); // <nothing>
7878
```
7979

80-
As a common solution, all properties that describe the state of a particular object, like `stomach` above, are usually written into that object. That prevents such problems.
80+
As a common solution, all properties that describe the state of a particular object, like `stomach` above, should be written into that object. That prevents such problems.

1-js/08-prototypes/01-prototype-inheritance/article.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ The method is automatically taken from the prototype, like this:
9393

9494
The prototype chain can be longer:
9595

96-
9796
```js run
9897
let animal = {
9998
eats: true,
@@ -128,11 +127,10 @@ Now if we read something from `longEar`, and it's missing, JavaScript will look
128127
There are only two limitations:
129128

130129
1. The references can't go in circles. JavaScript will throw an error if we try to assign `__proto__` in a circle.
131-
2. The value of `__proto__` can be either an object or `null`, other types (like primitives) are ignored.
130+
2. The value of `__proto__` can be either an object or `null`. Other types are ignored.
132131

133132
Also it may be obvious, but still: there can be only one `[[Prototype]]`. An object may not inherit from two others.
134133

135-
136134
```smart header="`__proto__` is a historical getter/setter for `[[Prototype]]`"
137135
It's a common mistake of novice developers not to know the difference between these two.
138136

@@ -178,7 +176,7 @@ From now on, `rabbit.walk()` call finds the method immediately in the object and
178176

179177
![](proto-animal-rabbit-walk-2.svg)
180178

181-
That's for data properties only, not for accessors. If a property is a getter/setter, then it behaves like a function: getters/setters are looked up in the prototype.
179+
Accessor properties are an exception, as assignment is handled by a setter function. So writing to such a property is actually the same as calling a function.
182180

183181
For that reason `admin.fullName` works correctly in the code below:
184182

0 commit comments

Comments
 (0)