Skip to content

Commit d43276a

Browse files
authored
Added clarification
The solution explanation is not very obvious so added another example to make things clear
1 parent 2b5ac97 commit d43276a

File tree

1 file changed

+11
-0
lines changed
  • 1-js/04-object-basics/04-object-methods/4-object-property-this

1 file changed

+11
-0
lines changed

1-js/04-object-basics/04-object-methods/4-object-property-this/solution.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ The value of `this` is one for the whole function, code blocks and object litera
2222

2323
So `ref: this` actually takes current `this` of the function.
2424

25+
We can rewrite the function and return the same `this` with `undefined` value:
26+
27+
```js run
28+
function makeUser(){
29+
return this; // this time there's no object literal
30+
}
31+
32+
alert( makeUser().name ); // Error: Cannot read property 'name' of undefined
33+
```
34+
As you can see the result of `alert( makeUser().name )` is the same as `alert( user.ref.name )`
35+
2536
Here's the opposite case:
2637

2738
```js run

0 commit comments

Comments
 (0)