Skip to content

Instantly share code, notes, and snippets.

@kristyburge
Last active August 1, 2018 14:17
Show Gist options
  • Save kristyburge/e72d7da436130532a9fba965addc1a51 to your computer and use it in GitHub Desktop.
Save kristyburge/e72d7da436130532a9fba965addc1a51 to your computer and use it in GitHub Desktop.
Nested Objects Example
var obj1 = {
hello: function() {
console.log('Hello world');
return this;
},
obj2: {
breed: 'dog',
speak: function(){
console.log('woof!');
return this;
}
}
};
console.log(obj1);
console.log(obj1.hello()); // logs 'Hello world' and returns obj1
console.log(obj1.obj2);
console.log(obj1.obj2.speak()); // logs 'woof!' and returns obj2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment