commit
47d186598a
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 the result of `alert( user.ref.name )` from the previous example.
|
||||||
|
|
||||||
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