Skip to content

Commit a894b9e

Browse files
committed
minor
1 parent 0757d51 commit a894b9e

File tree

1 file changed

+6
-7
lines changed
  • 1-js/08-prototypes/01-prototype-inheritance

1 file changed

+6
-7
lines changed

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

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

102102
The prototype chain can be longer:
103103

104-
105104
```js run
106105
let animal = {
107106
eats: true,
@@ -131,10 +130,10 @@ alert(longEar.jumps); // true (from rabbit)
131130

132131
![](proto-animal-rabbit-chain.svg)
133132

134-
There are actually only two limitations:
133+
There are only two limitations:
135134

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

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

@@ -171,7 +170,7 @@ From now on, `rabbit.walk()` call finds the method immediately in the object and
171170

172171
![](proto-animal-rabbit-walk-2.svg)
173172

174-
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.
173+
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.
175174

176175
For that reason `admin.fullName` works correctly in the code below:
177176

@@ -247,7 +246,7 @@ The resulting picture:
247246

248247
![](proto-animal-rabbit-walk-3.svg)
249248

250-
If we had other objects like `bird`, `snake` etc inheriting from `animal`, they would also gain access to methods of `animal`. But `this` in each method would be the corresponding object, evaluated at the call-time (before dot), not `animal`. So when we write data into `this`, it is stored into these objects.
249+
If we had other objects like `bird`, `snake` etc inheriting from `animal`, they would also gain access to methods of `animal`. But `this` in each method call would be the corresponding object, evaluated at the call-time (before dot), not `animal`. So when we write data into `this`, it is stored into these objects.
251250

252251
As a result, methods are shared, but the object state is not.
253252

@@ -313,8 +312,8 @@ Note, there's one funny thing. Where is the method `rabbit.hasOwnProperty` comin
313312

314313
The answer is simple: it's not enumerable. Just like all other properties of `Object.prototype`, it has `enumerable:false` flag. That's why they are not listed.
315314

316-
```smart header="All other iteration methods ignore inherited properties"
317-
All other key/value-getting methods, such as `Object.keys`, `Object.values` and so on ignore inherited properties.
315+
```smart header="Almost all other key/value-getting methods ignore inherited properties"
316+
Almost all other key/value-getting methods, such as `Object.keys`, `Object.values` and so on ignore inherited properties.
318317
319318
They only operate on the object itself. Properties from the prototype are taken into account.
320319
```

0 commit comments

Comments
 (0)