Skip to content

Instantly share code, notes, and snippets.

@mornir
Created January 1, 2018 21:19
Show Gist options
  • Select an option

  • Save mornir/fd8715e1649cffb70fa88f3f3da4518e to your computer and use it in GitHub Desktop.

Select an option

Save mornir/fd8715e1649cffb70fa88f3f3da4518e to your computer and use it in GitHub Desktop.
'This' in nested objects
//'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