Skip to content

Instantly share code, notes, and snippets.

@kakopappa
Created November 21, 2019 04:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kakopappa/dc80870820455a3106fcbf41df512851 to your computer and use it in GitHub Desktop.
Save kakopappa/dc80870820455a3106fcbf41df512851 to your computer and use it in GitHub Desktop.
javascript classes example
book.js
class Book {
async doSomething() {
console.log("Do something!");
}
constructor() {
this.id = 'id_1';
}
set name(name) {
this._name = name.charAt(0).toUpperCase() + name.slice(1);
}
get name() {
return this._name;
}
sayHello() {
console.log('Hello, my name is ' + this.name + ', I have ID: ' + this.id);
}
}
module.exports.Book = Book;
app.js
const { Book } = require('./book.js');
var book = new Book();
book.sayHello();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment