Skip to content

Commit 4de9c99

Browse files
authored
Revert "Prototype methods, objects without __proto__"
1 parent 39af0cc commit 4de9c99

File tree

6 files changed

+109
-129
lines changed

6 files changed

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

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

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

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

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

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

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

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.
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.
3030

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

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-
# Añadir toString al diccionario
5+
# Add toString to the dictionary
66

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

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.
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.
1010

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

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

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

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

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

29-
// tu toString en accion
30-
alert(dictionary); // "manzana,__proto__"
29+
// your toString in action
30+
alert(dictionary); // "apple,__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-
La primera llamada tiene `this == rabbit`, las otras tienen `this` igual a `Rabbit.prototype`, porque en realidad es el objeto antes del punto.
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.
33

4-
Entonces, solo la primera llamada muestra `Rabbit`, las otras muestran `undefined`:
4+
So only the first call shows `Rabbit`, other ones show `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("Conejo");
14+
let rabbit = new Rabbit("Rabbit");
1515

16-
rabbit.sayHi(); // Conejo
16+
rabbit.sayHi(); // Rabbit
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-
# La diferencia entre llamadas
5+
# The difference between calls
66

7-
Creemos un nuevo objeto `rabbit`:
7+
Let's create a new `rabbit` object:
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("Conejo");
17+
let rabbit = new Rabbit("Rabbit");
1818
```
1919

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

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

0 commit comments

Comments
 (0)