Skip to content

Commit 39af0cc

Browse files
authored
Merge pull request #195 from cortizg/es.javascript.info.1-08-04-pm
Prototype methods, objects without __proto__
2 parents 417b7f8 + c1a6bfb commit 39af0cc

File tree

6 files changed

+129
-109
lines changed

6 files changed

+129
-109
lines changed
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11

2-
The method can take all enumerable keys using `Object.keys` and output their list.
2+
El método puede tomar todas las claves enumerables usando `Object.keys` y generar su lista.
33

4-
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.
4+
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.
55

66
```js run
77
*!*
88
let dictionary = Object.create(null, {
9-
toString: { // define toString property
10-
value() { // the value is a function
9+
toString: { // define la propiedad toString
10+
value() { // el valor es una funcion
1111
return Object.keys(this).join();
1212
}
1313
}
1414
});
1515
*/!*
1616

17-
dictionary.apple = "Apple";
18-
dictionary.__proto__ = "test";
17+
dictionary.apple = "Manzana";
18+
dictionary.__proto__ = "prueba";
1919

20-
// apple and __proto__ is in the loop
20+
// manzana y __proto__ están en el ciclo
2121
for(let key in dictionary) {
22-
alert(key); // "apple", then "__proto__"
22+
alert(key); // "manzana", despues "__proto__"
2323
}
2424

25-
// comma-separated list of properties by toString
26-
alert(dictionary); // "apple,__proto__"
25+
// lista de propiedades separadas por comas por toString
26+
alert(dictionary); // "manzana,__proto__"
2727
```
2828

29-
When we create a property using a descriptor, its flags are `false` by default. So in the code above, `dictionary.toString` is non-enumerable.
29+
Cuando creamos una propiedad usando un descriptor, sus banderas son `false` por defecto. Entonces, en el código anterior, `dictionary.toString` no es enumerable.
3030

31-
See the the chapter [](info:property-descriptors) for review.
31+
Consulte el capítulo [](info:property-descriptors) para su revisión.

1-js/08-prototypes/04-prototype-methods/2-dictionary-tostring/task.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@ importance: 5
22

33
---
44

5-
# Add toString to the dictionary
5+
# Añadir toString al diccionario
66

7-
There's an object `dictionary`, created as `Object.create(null)`, to store any `key/value` pairs.
7+
Hay un objeto `dictionary`, creado como `Object.create(null)`, para almacenar cualquier par `clave/valor`.
88

9-
Add method `dictionary.toString()` into it, that should return a comma-delimited list of keys. Your `toString` should not show up in `for..in` over the object.
9+
Agrega el método `dictionary.toString()`, que debería devolver una lista de claves delimitadas por comas. Tu `toString` no debe aparecer al iterar un `for..in` sobre el objeto.
1010

11-
Here's how it should work:
11+
Así es como debería funcionar:
1212

1313
```js
1414
let dictionary = Object.create(null);
1515

1616
*!*
17-
// your code to add dictionary.toString method
17+
// tu código para agregar el método dictionary.toString
1818
*/!*
1919

20-
// add some data
21-
dictionary.apple = "Apple";
22-
dictionary.__proto__ = "test"; // __proto__ is a regular property key here
20+
// agregar algunos datos
21+
dictionary.apple = "Manzana";
22+
dictionary.__proto__ = "prueba"; // // aquí proto es una propiedad clave común
2323

24-
// only apple and __proto__ are in the loop
24+
// solo manzana y __proto__ están en el ciclo
2525
for(let key in dictionary) {
26-
alert(key); // "apple", then "__proto__"
26+
alert(key); // "manzana", despues "__proto__"
2727
}
2828

29-
// your toString in action
30-
alert(dictionary); // "apple,__proto__"
29+
// tu toString en accion
30+
alert(dictionary); // "manzana,__proto__"
3131
```

1-js/08-prototypes/04-prototype-methods/3-compare-calls/solution.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

2-
The first call has `this == rabbit`, the other ones have `this` equal to `Rabbit.prototype`, because it's actually the object before the dot.
2+
La primera llamada tiene `this == rabbit`, las otras tienen `this` igual a `Rabbit.prototype`, porque en realidad es el objeto antes del punto.
33

4-
So only the first call shows `Rabbit`, other ones show `undefined`:
4+
Entonces, solo la primera llamada muestra `Rabbit`, las otras muestran `undefined`:
55

66
```js run
77
function Rabbit(name) {
@@ -11,9 +11,9 @@ Rabbit.prototype.sayHi = function() {
1111
alert( this.name );
1212
}
1313

14-
let rabbit = new Rabbit("Rabbit");
14+
let rabbit = new Rabbit("Conejo");
1515

16-
rabbit.sayHi(); // Rabbit
16+
rabbit.sayHi(); // Conejo
1717
Rabbit.prototype.sayHi(); // undefined
1818
Object.getPrototypeOf(rabbit).sayHi(); // undefined
1919
rabbit.__proto__.sayHi(); // undefined

1-js/08-prototypes/04-prototype-methods/3-compare-calls/task.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ importance: 5
22

33
---
44

5-
# The difference between calls
5+
# La diferencia entre llamadas
66

7-
Let's create a new `rabbit` object:
7+
Creemos un nuevo objeto `rabbit`:
88

99
```js
1010
function Rabbit(name) {
@@ -14,10 +14,10 @@ Rabbit.prototype.sayHi = function() {
1414
alert(this.name);
1515
};
1616

17-
let rabbit = new Rabbit("Rabbit");
17+
let rabbit = new Rabbit("Conejo");
1818
```
1919

20-
These calls do the same thing or not?
20+
Estas llamadas hacen lo mismo o no?
2121

2222
```js
2323
rabbit.sayHi();

0 commit comments

Comments
 (0)