Skip to content

Instantly share code, notes, and snippets.

@nire0510
Created October 27, 2015 21:35
Show Gist options
  • Save nire0510/7b831a99dd0db7ae79af to your computer and use it in GitHub Desktop.
Save nire0510/7b831a99dd0db7ae79af to your computer and use it in GitHub Desktop.
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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment