Created
January 1, 2018 21:19
-
-
Save mornir/fd8715e1649cffb70fa88f3f3da4518e to your computer and use it in GitHub Desktop.
'This' in nested objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //'this' can only access properties in its current level or below using the dot operator (this.friends.amis). It can access upper levels by referencing the object name (nestedObject.nom) | |
| // no matter how nested the object is, 'this' is an arrow function will always reference the context right **outside** the object. | |
| let nestedObject = { | |
| nom: 'Jérôme', | |
| logDenis() { | |
| console.log(this.friends.amis) | |
| }, | |
| friends: { | |
| nom: 'Antoine', | |
| amis: 'Denis', | |
| fn() { | |
| console.log(nestedObject.nom) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment