Created
February 11, 2019 01:11
-
-
Save Maccauhuru/5c73feba940f3d3b09677cc4ccb51177 to your computer and use it in GitHub Desktop.
Object Method ES5
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
//define Book as an object constructor function | |
function Book(name,author) { | |
this.name = name; | |
this.author = author; | |
} | |
//add getBookDetails method to object prototype | |
Book.prototype.getBookDetails = function (){ | |
return `The book ${this.name} was written by ${this.author}`; | |
} | |
//add some new books | |
const jspatterns = new Book('JavaScript Patterns','Stoyan Stefanov'); | |
const masteringnodejs = new Book ('Mastering Node.js','Sandro Pasquali'); | |
//call getBookDetails method on each defined book | |
jspatterns.getBookDetails();// "The book JavaScript Patterns was written by Stoyan Stefanov" | |
masteringnodejs.getBookDetails();// "The book Mastering Node.js was written by Sandro Pasquali" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment