1- ** Answer: an error.**
1+ ** Respuesta: un error.**
22
3- Try it :
3+ Pruébalo :
44``` js run
55function makeUser () {
66 return {
@@ -11,29 +11,29 @@ function makeUser() {
1111
1212let user = makeUser ();
1313
14- alert ( user .ref .name ); // Error: Cannot read property 'name' of undefined
14+ alert ( user .ref .name ); // Error: No se puede leer la propiedad 'name' de undefined
1515```
1616
17- That's because rules that set ` this ` do not look at object definition. Only the moment of call matters .
17+ Esto es porque las reglas que establecen el ` this ` no buscan en la definición del objeto. Solamente importa el momento en que se llama .
1818
19- Here the value of ` this ` inside ` makeUser() ` is ` undefined ` , because it is called as a function, not as a method with "dot" syntax .
19+ Aquí el valor de ` this ` dentro de ` makeUser() ` es ` undefined ` , porque es llamado como una función, no como un método con sintaxis de punto .
2020
21- The value of ` this ` is one for the whole function, code blocks and object literals do not affect it .
21+ El valor de ` this ` es uno para la función entera; bloques de código y objetos literales no lo afectan .
2222
23- So ` ref: this ` actually takes current ` this ` of the function .
23+ Entonces ` ref: this ` en realidad toma el ` this ` actual de la función .
2424
25- We can rewrite the function and return the same ` this ` with ` undefined ` value :
25+ Podemos reescribir la función y devolver el mismo ` this ` con valor ` undefined ` :
2626
2727``` js run
2828function makeUser (){
29- return this ; // this time there's no object literal
29+ return this ; // esta vez no hay objeto literal
3030}
3131
32- alert ( makeUser ().name ); // Error: Cannot read property 'name' of undefined
32+ alert ( makeUser ().name ); // Error: No se puede leer la propiedad 'name' de undefined
3333```
34- As you can see the result of ` alert( makeUser().name ) ` is the same as the result of ` alert( user.ref.name ) ` from the previous example .
34+ Como puedes ver el resultado de ` alert( makeUser().name ) ` es el mismo que el resultado de ` alert( user.ref.name ) ` del ejemplo anterior .
3535
36- Here's the opposite case :
36+ Aquí está el caso opuesto :
3737
3838``` js run
3939function makeUser () {
@@ -52,4 +52,4 @@ let user = makeUser();
5252alert ( user .ref ().name ); // John
5353```
5454
55- Now it works, because ` user.ref() ` is a method. And the value of ` this ` is set to the object before dot ` . ` .
55+ Ahora funciona, porque ` user.ref() ` es un método. Y el valor de ` this ` es establecido al del objeto delante del punto ` . ` .
0 commit comments