Created
July 16, 2015 14:46
-
-
Save wilk/8df387306210ce3e896c to your computer and use it in GitHub Desktop.
ES6 Class
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, surname) { | |
this.name = name | |
this.surname = surname | |
} | |
introduce() { | |
console.log(`Hi, my name is ${this.name} ${this.surname}`) | |
} | |
static type() { | |
console.log("I'm a Person") | |
} | |
} | |
class Developer extends Person { | |
constructor(name, surname, skill) { | |
super(name, surname) // Person.constructor | |
this.skill = skill | |
} | |
introduce() { // override | |
console.log(`Hi, my name is ${this.name} ${this.surname} and I know ${this.skill}`) | |
} | |
} | |
let mario = new Person('Mario', 'Bros') | |
mario.introduce() // Hi, my name is Mario Bros | |
Person.type() // I'm a Person | |
let luigi = new Developer('Luigi', 'Bros', 'ES6') // inherits every props and methods, even those static | |
luigi.introduce() // Hi, my name is Luigi Bros and I know ES6 | |
Developer.type() // I'm a Person |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment