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 1/2] 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 From 0de5046a40bee9f0855e1a09f38a6acf7a5e08db Mon Sep 17 00:00:00 2001 From: koala-lava <15828770+koala-lava@users.noreply.github.com> Date: Sun, 1 Dec 2019 20:13:36 +0700 Subject: [PATCH 2/2] Update solution.md --- .../04-object-methods/4-object-property-this/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 6326a9a7..c1aaf4f9 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 @@ -31,7 +31,7 @@ function makeUser(){ 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 )` +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. Here's the opposite case: