Class keyword in Javascript

I know this is a old post, but as of today i.e with the advent of ECMAScript 6 we can declare javascript classes.

The syntax goes as follows :

class Person{
  constructor(name){
    this.name = name;
  }
  printName(){
    console.log('Name is '+this.name);
  }
}
var john = new Person('John Doe');
john.printName(); // This prints 'Name is John Doe'

A complete guide to this can be found in this post

Leave a Comment