Classes in ES6

Bashar Ayyash
1 min readOct 7, 2015

--

This is a part of Starter to ES6

In ES6 JavaScript programmers will be able to build their applications using object-oriented class-based approach.

class Greeting {
msg;
constructor(msg){
this.msg = msg;
}

greet(){
return `Hello ${this.msg}`;
}
}
class Person extends Greeting{
name;
constructor(name, msg){
super(msg);
this.name = name;
}

personGreeting(){
console.log(`${this.name} said, ${super.greet()}`);
}
}

let sam = new Person('Sam', 'World');
sam.personGreeting();

The above example shows how to use classes in ES6 and use inheritance (extends).

This is a part of Starter to ES6

--

--

Bashar Ayyash

Front End Developer, I’m confident that Vue.js is as powerful as React, but way more flexible and a lot easier to learn