Merge pull request #1603 from koala-lava/patch-2

Added clarification
This commit is contained in:
Ilya Kantor 2019-12-01 19:06:10 +03:00 committed by GitHub
commit 47d186598a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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