Last active
August 1, 2018 14:17
-
-
Save kristyburge/e72d7da436130532a9fba965addc1a51 to your computer and use it in GitHub Desktop.
Nested Objects Example
This file contains 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
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