This commit is contained in:
Ilya Kantor 2020-05-28 11:07:34 +03:00 committed by GitHub
parent d36675ed33
commit cd2c7ce3c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,11 +1,11 @@
# Property getters and setters # Property getters and setters
There are two kinds of properties. There are two kinds of object properties.
The first kind is *data properties*. We already know how to work with them. All properties that we've been using until now were data properties. The first kind is *data properties*. We already know how to work with them. All properties that we've been using until now were data properties.
The second type of properties is something new. It's *accessor properties*. They are essentially functions that work on getting and setting a value, but look like regular properties to an external code. The second type of properties is something new. It's *accessor properties*. They are essentially functions that execute on getting and setting a value, but look like regular properties to an external code.
## Getters and setters ## Getters and setters
@ -53,7 +53,7 @@ alert(user.fullName); // John Smith
*/!* */!*
``` ```
From outside, an accessor property looks like a regular one. That's the idea of accessor properties. We don't *call* `user.fullName` as a function, we *read* it normally: the getter runs behind the scenes. From the outside, an accessor property looks like a regular one. That's the idea of accessor properties. We don't *call* `user.fullName` as a function, we *read* it normally: the getter runs behind the scenes.
As of now, `fullName` has only a getter. If we attempt to assign `user.fullName=`, there will be an error: As of now, `fullName` has only a getter. If we attempt to assign `user.fullName=`, there will be an error: