Skip to content

Instantly share code, notes, and snippets.

@Maccauhuru
Last active January 28, 2019 02:39
Show Gist options
  • Save Maccauhuru/57b2ab0b7de0475e84192bb31b1d8da5 to your computer and use it in GitHub Desktop.
Save Maccauhuru/57b2ab0b7de0475e84192bb31b1d8da5 to your computer and use it in GitHub Desktop.
Example Object Definition
//lets define an object called book
const book = {};
//lets add two properties to our book object
book.name = "Eloquent JavaScript: A Modern Introduction to Programming";
book.author = "Marijn Haverbeke"
//lets define a method to get the book details
book.getBookDetails = function (){
return "The book " + this.name + " was written by " + this.author;
}
console.log(book.name);//"Eloquent JavaScript: A Modern Introduction to Programming"
console.log(book.author);//"Marijn Haverbeke"
console.log(book.getBookDetails());
//"The book Eloquent JavaScript: A Modern Introduction to Programming was written by Marijn Haverbeke"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment