nire0510
10/27/2015 - 9:35 PM

ES6/2015 class

ES6/2015 class

'use strict';

class Person {
  constructor (strName) {
    this._name = strName;
    console.log('My name is', this._name);
  }
  eat () {
    console.log(this._name, 'is eating!');
  }
  get name () {
    return this._name;
  }
  set age (intAge) {
    this._age = intAge;
    console.log(this._name, 'is', this._age, 'years old');
  }
}

class Student extends Person {
  constructor (strName, strInstitute) {
    super(strName);
  }
  
  learn () {
    console.log(this._name, 'is learning!');
  }
}

var p = new Person('Alma');
p.eat();
p.age = 12;

var s = new Student('Roy');
s.learn();