This commit is contained in:
Ilya Kantor 2019-05-19 19:37:27 +03:00
parent e7d6d4a8db
commit dd106baf4c

View file

@ -232,7 +232,7 @@ new User().sayHi(); // Hello
## Getters/setters, other shorthands ## Getters/setters, other shorthands
Classes also include getters/setters, generators, computed properties etc. Just like literal objects, classes may include getters/setters, generators, computed properties etc.
Here's an example for `user.name` implemented using `get/set`: Here's an example for `user.name` implemented using `get/set`:
@ -325,24 +325,6 @@ The property is not placed into `User.prototype`. Instead, it is created by `new
## Summary ## Summary
JavaScript provides many ways to create a class.
First, as per the general object-oriented terminology, a class is something that provides "object templates", allows to create same-structured objects.
When we say "a class", that doesn't necessary means the `class` keyword.
This is a class:
```js
function User(name) {
this.sayHi = function() {
alert(name);
}
}
```
...But in most cases `class` keyword is used, as it provides great syntax and many additional features.
The basic class syntax looks like this: The basic class syntax looks like this:
```js ```js
@ -363,6 +345,6 @@ class MyClass {
} }
``` ```
`MyClass` is technically a function, while methods are written to `MyClass.prototype`. `MyClass` is technically a function (the one that we provide as `constructor`), while methods, getters and settors are written to `MyClass.prototype`.
In the next chapters we'll learn more about classes, including inheritance and other features. In the next chapters we'll learn more about classes, including inheritance and other features.