Skip to content

Commit 47d1865

Browse files
authored
Merge pull request #1603 from koala-lava/patch-2
Added clarification
2 parents 22888ae + 0de5046 commit 47d1865

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 the result of `alert( user.ref.name )` from the previous example.
35+
2536
Here's the opposite case:
2637

2738
```js run

0 commit comments

Comments
 (0)