Update article.md

Grammar
This commit is contained in:
hrodward 2019-10-21 11:41:14 +02:00 committed by GitHub
parent 30e3fa7237
commit 3c8ae3090d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -34,7 +34,7 @@ rabbit.__proto__ = animal;
```smart header="`__proto__` is a historical getter/setter for `[[Prototype]]`"
Please note that `__proto__` is *not the same* as `[[Prototype]]`. That's a getter/setter for it.
It exists for historical reasons, in modern language it is replaced with functions `Object.getPrototypeOf/Object.setPrototypeOf` that also get/set the prototype. We'll study the reasons for that and these functions later.
It exists for historical reasons. In modern language it is replaced with functions `Object.getPrototypeOf/Object.setPrototypeOf` that also get/set the prototype. We'll study the reasons for that and these functions later.
By the specification, `__proto__` must only be supported by browsers, but in fact all environments including server-side support it. For now, as `__proto__` notation is a little bit more intuitively obvious, we'll use it in the examples.
```
@ -203,7 +203,7 @@ Here in the line `(*)` the property `admin.fullName` has a getter in the prototy
## The value of "this"
An interesting question may arise in the example above: what's the value of `this` inside `set fullName(value)`? Where the properties `this.name` and `this.surname` are written: into `user` or `admin`?
An interesting question may arise in the example above: what's the value of `this` inside `set fullName(value)`? Where are the properties `this.name` and `this.surname` written: into `user` or `admin`?
The answer is simple: `this` is not affected by prototypes at all.
@ -246,13 +246,13 @@ 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.
## for..in loop
The `for..in` loops over inherited properties too.
The `for..in` loop iterates over inherited properties too.
For instance:
@ -267,7 +267,7 @@ let rabbit = {
};
*!*
// Object.keys only return own keys
// Object.keys only returns own keys
alert(Object.keys(rabbit)); // jumps
*/!*