Skip to content

Instantly share code, notes, and snippets.

@wilk
Created July 16, 2015 14:46
Show Gist options
  • Save wilk/8df387306210ce3e896c to your computer and use it in GitHub Desktop.
Save wilk/8df387306210ce3e896c to your computer and use it in GitHub Desktop.
ES6 Class
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