-
Notifications
You must be signed in to change notification settings - Fork 231
Property getters and setters #194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
84d9a86
62996fc
05a92e5
f9b2439
78810a6
1ddc056
e9b0519
0988760
3cee180
c19bdf8
67303a9
0cb05bb
fc70112
039e27b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,31 +1,31 @@ | ||||||
|
||||||
# Property getters and setters | ||||||
|
||||||
There are two kinds of properties. | ||||||
Hay dos tipos de propiedades. | ||||||
|
||||||
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. | ||||||
El primer tipo son las *propiedades de los datos*. Ya sabemos cómo trabajar con ellas. En realidad, todas las propiedades que hemos estado usando hasta ahora eran propiedades de datos. | ||||||
|
||||||
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. | ||||||
El segundo tipo de propiedades es algo nuevo. Son las *propiedades de acceso*. Estas son esencialmente funciones que, trabajan en la obtención y asignación de un valor, pero parecen propiedades normales para un código externo. | ||||||
rainvare marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
||||||
## Getters and setters | ||||||
|
||||||
Accessor properties are represented by "getter" and "setter" methods. In an object literal they are denoted by `get` and `set`: | ||||||
Las propiedades de acceso están representadas por los métodos "getter" y "setter". En un objeto con la notación literal se denotan por "get" y "set": | ||||||
|
Las propiedades de acceso están representadas por los métodos "getter" y "setter". En un objeto con la notación literal se denotan por "get" y "set": | |
Las propiedades de acceso se representan por métodos "getter" y "setter" (de obtención y asignación). Propiamente en un objeto se denotan por `get` y `set`: |
rainvare marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
joaquinelio marked this conversation as resolved.
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahora queremos añadir una propiedad de "nombre completo", que debería ser "John Smith". Por supuesto, no queremos copiar-pegar la información existente, así que podemos aplicarla como un acceso: | |
Ahora queremos añadir una propiedad `fullName`, que debería ser "John Smith". Por supuesto, no queremos copiar-pegar la información existente, así que podemos implementarla como propiedad de acceso: |
rainvare marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
joaquinelio marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
rainvare marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
El 30 nov, Ilya borró el smat header. Suele hacer esas cosas: por legibilidad, por redundante, por equivocado.
Deberías borrar el bloque desde
98 "Accessor properties are only accessible with get/set" hasta 106
y QUEDA:
97 Como resultado, tenemos una propiedad virtual fullName
que puede leerse y escribirse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Por ejemplo, para crear un acceso " Nombre Completo" con "Definir Propiedad", podemos pasar un descriptor con `get` y `set`: | |
Por ejemplo, para crear un acceso `fullName` con `defineProperty`, podemos pasar un descriptor con `get` y `set`: |
Uh oh!
There was an error while loading. Please reload this page.