Last active
January 28, 2019 03:46
-
-
Save Maccauhuru/c55f90bd8901dee89156bdda49eaec50 to your computer and use it in GitHub Desktop.
Example Object Constructor Function
This file contains hidden or 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; | |
this.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