Skip to content

Instantly share code, notes, and snippets.

@worldofprasanna
Last active March 13, 2016 06:09
Show Gist options
  • Save worldofprasanna/71f4040ddf43bf2c6ab7 to your computer and use it in GitHub Desktop.
Save worldofprasanna/71f4040ddf43bf2c6ab7 to your computer and use it in GitHub Desktop.
Class in ES6
class Person {
constructor(name){
this.name = name;
}
}
class Employee extends Person {
constructor(id, name){
super(name);
this.id = id;
}
static type(){
return 'Employee';
}
toString(){
return `Employee: id = ${this.id}, name = ${this.name}`;
}
}
let e = new Employee(1, 'Prasanna');
console.log(e.toString());
console.log(Employee.type());
// "Employee: id = 1, name = Prasanna"
// "Employee"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment