Snippets Collections
class Pencil {
  constructor(price) {
    this.price = price;
  }

  isExpensive() {
    return this.price >= 10;
  }
}

//usage
const bic = new Pencil(3);
bic.isExpensive();
star

Wed Apr 05 2023 16:11:13 GMT+0000 (Coordinated Universal Time) https://codetogo.io/how-to-define-a-class-in-javascript/

#javascript #class #generate #constructor #this

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension