Skip to content

Commit 0feb589

Browse files
authored
Merge pull request #412 from Arnau-Ninerola/master
Translate 1.9.3.3 task and solution
2 parents 986f770 + a7df668 commit 0feb589

File tree

2 files changed

+34
-34
lines changed

2 files changed

+34
-34
lines changed
Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,81 @@
1-
First, let's see why the latter code doesn't work.
1+
Primero, veamos por qué el código anterior no funciona.
22

3-
The reason becomes obvious if we try to run it. An inheriting class constructor must call `super()`. Otherwise `"this"` won't be "defined".
3+
La razón se vuelve evidente si intentamos ejecutarlo. Un constructor de clase heredado tiene que llamar a `super()`. De lo contrario `"this"` no será "definido".
44

5-
So here's the fix:
5+
Así que aquí está la solución:
66

77
```js run
88
class Rabbit extends Object {
99
constructor(name) {
1010
*!*
11-
super(); // need to call the parent constructor when inheriting
11+
super(); // necesita llamar al constructor padre cuando se hereda
1212
*/!*
1313
this.name = name;
1414
}
1515
}
1616

1717
let rabbit = new Rabbit("Rab");
1818

19-
alert( rabbit.hasOwnProperty('name') ); // true
19+
alert( rabbit.hasOwnProperty('name') ); // verdadero
2020
```
2121

22-
But that's not all yet.
22+
Pero eso no es todo.
2323

24-
Even after the fix, there's still important difference in `"class Rabbit extends Object"` versus `class Rabbit`.
24+
Incluso después de arreglarlo, aún existe una diferencia importante en `"class Rabbit extends Object"` versus `class Rabbit`.
2525

26-
As we know, the "extends" syntax sets up two prototypes:
26+
Como sabemos, la sintaxis "extends" configura dos prototipos:
2727

28-
1. Between `"prototype"` of the constructor functions (for methods).
29-
2. Between the constructor functions themselves (for static methods).
28+
1. Entre `"prototype"` de las funciones del constructor (para métodos).
29+
2. Entre las propias funciones del constructor (para métodos estáticos).
3030

31-
In our case, for `class Rabbit extends Object` it means:
31+
En nuestro caso, para `class Rabbit extends Object` significa:
3232

3333
```js run
3434
class Rabbit extends Object {}
3535

36-
alert( Rabbit.prototype.__proto__ === Object.prototype ); // (1) true
37-
alert( Rabbit.__proto__ === Object ); // (2) true
36+
alert( Rabbit.prototype.__proto__ === Object.prototype ); // (1) verdadero
37+
alert( Rabbit.__proto__ === Object ); // (2) verdadero
3838
```
3939

40-
So `Rabbit` now provides access to static methods of `Object` via `Rabbit`, like this:
40+
Entonces `Rabbit` ahora proporciona acceso a los métodos estáticos de `Object` a través de `Rabbit`, así:
4141

4242
```js run
4343
class Rabbit extends Object {}
4444

4545
*!*
46-
// normally we call Object.getOwnPropertyNames
46+
// normalmente llamamos a Object.getOwnPropertyNames
4747
alert ( Rabbit.getOwnPropertyNames({a: 1, b: 2})); // a,b
4848
*/!*
4949
```
5050

51-
But if we don't have `extends Object`, then `Rabbit.__proto__` is not set to `Object`.
51+
Pero si no tenemos `extends Object`, entonces `Rabbit.__proto__` no está definido como `Object`.
5252

53-
Here's the demo:
53+
Aquí está la demostración:
5454

5555
```js run
5656
class Rabbit {}
5757

58-
alert( Rabbit.prototype.__proto__ === Object.prototype ); // (1) true
59-
alert( Rabbit.__proto__ === Object ); // (2) false (!)
60-
alert( Rabbit.__proto__ === Function.prototype ); // as any function by default
58+
alert( Rabbit.prototype.__proto__ === Object.prototype ); // (1) verdadero
59+
alert( Rabbit.__proto__ === Object ); // (2) falso (!)
60+
alert( Rabbit.__proto__ === Function.prototype ); // como cualquier función por defecto
6161

6262
*!*
63-
// error, no such function in Rabbit
63+
// error, no existe esta función en Rabbit
6464
alert ( Rabbit.getOwnPropertyNames({a: 1, b: 2})); // Error
6565
*/!*
6666
```
6767

68-
So `Rabbit` doesn't provide access to static methods of `Object` in that case.
68+
Entonces `Rabbit` no proporciona acceso a métodos estáticos de `Object` en este caso.
6969

70-
By the way, `Function.prototype` has "generic" function methods, like `call`, `bind` etc. They are ultimately available in both cases, because for the built-in `Object` constructor, `Object.__proto__ === Function.prototype`.
70+
Por cierto, `Function.prototype` tiene métodos de función "genéricos", como `call`, `bind` etc. Finalmente, están disponibles en ambos casos, por el `Object` que tiene el constructor incorporado `Object.__proto__ === Function.prototype`.
7171

72-
Here's the picture:
72+
Aquí está la imagen:
7373

7474
![](rabbit-extends-object.svg)
7575

76-
So, to put it short, there are two differences:
76+
Por lo tanto, en pocas palabras, existen dos diferencias:
7777

7878
| class Rabbit | class Rabbit extends Object |
7979
|--------------|------------------------------|
80-
| -- | needs to call `super()` in constructor |
80+
| -- | necesita llamar a `super()` en el constructor |
8181
| `Rabbit.__proto__ === Function.prototype` | `Rabbit.__proto__ === Object` |

1-js/09-classes/03-static-properties-methods/3-class-extend-object/task.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ importance: 3
22

33
---
44

5-
# Class extends Object?
5+
# ¿La clase extiende el objeto?
66

7-
As we know, all objects normally inherit from `Object.prototype` and get access to "generic" object methods like `hasOwnProperty` etc.
7+
Como sabemos, todos los objetos normalmente heredan de `Object.prototype` y obtienen acceso a métodos de objeto "genéricos" como `hasOwnProperty` etc.
88

9-
For instance:
9+
Por ejemplo:
1010

1111
```js run
1212
class Rabbit {
@@ -18,16 +18,16 @@ class Rabbit {
1818
let rabbit = new Rabbit("Rab");
1919

2020
*!*
21-
// hasOwnProperty method is from Object.prototype
22-
alert( rabbit.hasOwnProperty('name') ); // true
21+
// el método hasOwnProperty proviene de Object.prototype
22+
alert( rabbit.hasOwnProperty('name') ); // verdadero
2323
*/!*
2424
```
2525

26-
But if we spell it out explicitly like `"class Rabbit extends Object"`, then the result would be different from a simple `"class Rabbit"`?
26+
Pero si lo escribimos explícitamente como `"class Rabbit extends Object"`, entonces ¿el resultado sería diferente de una simple `"class Rabbit"`?
2727

28-
What's the difference?
28+
¿Cuál es la diferencia?
2929

30-
Here's an example of such code (it doesn't work -- why? fix it?):
30+
Aquí un ejemplo de dicho código (no funciona -- ¿por qué? ¿Arréglalo?):
3131

3232
```js
3333
class Rabbit extends Object {

0 commit comments

Comments
 (0)