From d43276a7f354526e297a46910bc03b094b924cf5 Mon Sep 17 00:00:00 2001 From: koala-lava <15828770+koala-lava@users.noreply.github.com> Date: Mon, 11 Nov 2019 19:54:21 +0700 Subject: [PATCH] Added clarification The solution explanation is not very obvious so added another example to make things clear --- .../4-object-property-this/solution.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/1-js/04-object-basics/04-object-methods/4-object-property-this/solution.md b/1-js/04-object-basics/04-object-methods/4-object-property-this/solution.md index ea00c970..6326a9a7 100644 --- a/1-js/04-object-basics/04-object-methods/4-object-property-this/solution.md +++ b/1-js/04-object-basics/04-object-methods/4-object-property-this/solution.md @@ -22,6 +22,17 @@ The value of `this` is one for the whole function, code blocks and object litera So `ref: this` actually takes current `this` of the function. +We can rewrite the function and return the same `this` with `undefined` value: + +```js run +function makeUser(){ + return this; // this time there's no object literal +} + +alert( makeUser().name ); // Error: Cannot read property 'name' of undefined +``` +As you can see the result of `alert( makeUser().name )` is the same as `alert( user.ref.name )` + Here's the opposite case: ```js run