Skip to content

Instantly share code, notes, and snippets.

@sevperez
Created September 18, 2018 16:15
Show Gist options
  • Save sevperez/09425de7268c2e757615d2d9cb4f475b to your computer and use it in GitHub Desktop.
Save sevperez/09425de7268c2e757615d2d9cb4f475b to your computer and use it in GitHub Desktop.
function announce(collection) {
console.log(collection.description);
collection.logItems();
}
var favoriteCities = {
items: {
"Denmark": "Copenhagen",
"Uganda": "Kampala",
"Uraguay": "Montevideo"
},
description: "My favorite cities around the world:",
logItems: function() {
Object.keys(this.items).forEach(function(key) {
console.log(this.items[key]);
}, this);
},
};
announce(favoriteCities);
// Logs:
// "My favorite cities around the world:"
// "Copenhagen"
// "Kampala"
// "Montevideo"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment