-
Notifications
You must be signed in to change notification settings - Fork 228
Prototype methods, objects without __proto__ #195
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
Merged
vplentinax
merged 6 commits into
javascript-tutorial:master
from
cortizg:es.javascript.info.1-08-04-pm
Jun 3, 2020
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d96e8e1
1-08-04-pm Traducido 15
cortizg e8f41e7
revisión 2020-05-29
cortizg ad49226
revision 2020-05-30
cortizg 9d22f63
revision 2020-05-30 2
cortizg 0b52022
revision 2020-05-30 3
cortizg c1a6bfb
Merge branch 'master' into es.javascript.info.1-08-04-pm
vplentinax File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
24 changes: 12 additions & 12 deletions
24
1-js/08-prototypes/04-prototype-methods/2-dictionary-tostring/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
|
||
The method can take all enumerable keys using `Object.keys` and output their list. | ||
El método puede tomar todas las claves enumerables usando `Object.keys` y generar su lista. | ||
|
||
To make `toString` non-enumerable, let's define it using a property descriptor. The syntax of `Object.create` allows us to provide an object with property descriptors as the second argument. | ||
Para hacer que `toString` no sea enumerable, definámoslo usando un descriptor de propiedad. La sintaxis de `Object.create` nos permite proporcionar un objeto con descriptores de propiedad como segundo argumento. | ||
|
||
```js run | ||
*!* | ||
let dictionary = Object.create(null, { | ||
toString: { // define toString property | ||
value() { // the value is a function | ||
toString: { // define la propiedad toString | ||
value() { // el valor es una funcion | ||
return Object.keys(this).join(); | ||
} | ||
} | ||
}); | ||
*/!* | ||
|
||
dictionary.apple = "Apple"; | ||
dictionary.__proto__ = "test"; | ||
dictionary.apple = "Manzana"; | ||
dictionary.__proto__ = "prueba"; | ||
|
||
// apple and __proto__ is in the loop | ||
// manzana y __proto__ están en el ciclo | ||
for(let key in dictionary) { | ||
alert(key); // "apple", then "__proto__" | ||
alert(key); // "manzana", despues "__proto__" | ||
} | ||
|
||
// comma-separated list of properties by toString | ||
alert(dictionary); // "apple,__proto__" | ||
// lista de propiedades separadas por comas por toString | ||
alert(dictionary); // "manzana,__proto__" | ||
``` | ||
|
||
When we create a property using a descriptor, its flags are `false` by default. So in the code above, `dictionary.toString` is non-enumerable. | ||
Cuando creamos una propiedad usando un descriptor, sus banderas son `false` por defecto. Entonces, en el código anterior, `dictionary.toString` no es enumerable. | ||
|
||
See the the chapter [](info:property-descriptors) for review. | ||
Consulte el capítulo [](info:property-descriptors) para su revisión. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.