Last active
February 26, 2019 14:27
-
-
Save Maccauhuru/9e1e49d100118fe46b01c65ed06fea63 to your computer and use it in GitHub Desktop.
ES6 Classes 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
//define Book as an object constructor function | |
class Book { | |
constructor(name,author,price){ | |
this.name = name; | |
this.author = author; | |
this.price = price; | |
} | |
getBookCost(){ | |
return `The book ${this.name} was written by ${this.author} and costs $${this.price}`; | |
} | |
} | |
const jspatterns = new Book('JavaScript Patterns','Stoyan Stefanov',12); | |
const masteringnodejs = new Book('Mastering Node.js','Sandro Pasquali',9); | |
//call getBookDetails method on each defined book | |
jspatterns.getBookCost();// "The book JavaScript Patterns was written by Stoyan Stefanov and costs $12" | |
masteringnodejs.getBookCost();// "The book Mastering Node.js was written by Sandro Pasquali and costs $9" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment