Added clarification
The solution explanation is not very obvious so added another example to make things clear
This commit is contained in:
parent
2b5ac971c1
commit
d43276a7f3
1 changed files with 11 additions and 0 deletions
|
@ -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.
|
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:
|
Here's the opposite case:
|
||||||
|
|
||||||
```js run
|
```js run
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue