ES6 Class Example

ES6 Class Example

code
Colin Stodd
ES6,Class,Example
16 Aug 2016 (Published)
16 Aug 2016 (Updated)

ES6 (The latest version of JavaScript) now supports classes. Here is a simple example of how to use it with a constructor function.

class Student {
  constructor( { name, age, interestLevel = 5 } = {} ) {
      this.name = name;
      this.age = age;
      this.interestLevel = interestLevel;
      this.grades = new Map();
  }
}
let colper = new Student({ name: 'Colper', age: 32 });

colper.grades.set('JavaScript', 'B');
colper.grades.set('Ruby', 'C');
colper.grades.set('Python', 'D');

console.log(Array.from(colper.grades));