Merge branch 'master' into patch-18

This commit is contained in:
Alexey Pyltsyn 2019-10-22 11:07:52 +03:00 committed by GitHub
commit 29ea8907d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 42 additions and 43 deletions

View file

@ -6,7 +6,7 @@ importance: 5
The task has two parts.
We have objects:
Given the following objects:
```js
let head = {

View file

@ -2,7 +2,7 @@ importance: 5
---
# Where it writes?
# Where does it write?
We have `rabbit` inheriting from `animal`.

View file

@ -2,11 +2,11 @@ importance: 5
---
# Why two hamsters are full?
# Why are both hamsters full?
We have two hamsters: `speedy` and `lazy` inheriting from the general `hamster` object.
When we feed one of them, the other one is also full. Why? How to fix it?
When we feed one of them, the other one is also full. Why? How can we fix it?
```js run
let hamster = {

View file

@ -246,7 +246,7 @@ The resulting picture:
![](proto-animal-rabbit-walk-3.svg)
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.
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.
As a result, methods are shared, but the object state is not.

View file

@ -20,7 +20,7 @@ alert( rabbit.eats ); // true
```
1. We added one more string (emphasized), what `alert` shows now?
1. We added one more string (emphasized). What will `alert` show now?
```js
function Rabbit() {}
@ -54,7 +54,7 @@ alert( rabbit.eats ); // true
alert( rabbit.eats ); // ?
```
3. Like this (replaced one line)?
3. And like this (replaced one line)?
```js
function Rabbit() {}

View file

@ -2,7 +2,7 @@
Remember, new objects can be created with a constructor function, like `new F()`.
If `F.prototype` is an object, then `new` operator uses it to set `[[Prototype]]` for the new object.
If `F.prototype` is an object, then the `new` operator uses it to set `[[Prototype]]` for the new object.
```smart
JavaScript had prototypal inheritance from the beginning. It was one of the core features of the language.
@ -158,9 +158,9 @@ Rabbit.prototype = {
In this chapter we briefly described the way of setting a `[[Prototype]]` for objects created via a constructor function. Later we'll see more advanced programming patterns that rely on it.
Everything is quite simple, just few notes to make things clear:
Everything is quite simple, just a few notes to make things clear:
- The `F.prototype` property (don't mess with `[[Prototype]]`) sets `[[Prototype]]` of new objects when `new F()` is called.
- The `F.prototype` property (don't mistake it for `[[Prototype]]`) sets `[[Prototype]]` of new objects when `new F()` is called.
- The value of `F.prototype` should be either an object or `null`: other values won't work.
- The `"prototype"` property only has such a special effect when set on a constructor function, and invoked with `new`.