Last active
March 13, 2016 06:09
-
-
Save worldofprasanna/71f4040ddf43bf2c6ab7 to your computer and use it in GitHub Desktop.
Class in ES6
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
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