This commit is contained in:
Ilya Kantor 2019-07-18 19:49:48 +03:00
parent 94a6933294
commit 34b51dc7ec

View file

@ -87,9 +87,9 @@ alert(typeof User); // function
What `class User {...}` construct really does is:
1. Creates a function named `User`, that becomes the result of the class declaration. The function code is taken from the `constructor` method (assumed empty if we don't write such method).
2. Stores all methods, such as `sayHi`, in `User.prototype`.
2. Stores class methods, such as `sayHi`, in `User.prototype`.
Afterwards, for new objects, when we call a method, it's taken from the prototype, just as described in the chapter <info:function-prototype>. So a `new User` object has access to class methods.
Afterwards, for `new User` objects, when we call a method, it's taken from the prototype, just as described in the chapter <info:function-prototype>. So the object has access to class methods.
We can illustrate the result of `class User` declaration as:
@ -97,7 +97,6 @@ We can illustrate the result of `class User` declaration as:
Here's the code to introspect it:
```js run
class User {
constructor(name) { this.name = name; }