Created
October 27, 2015 21:35
-
-
Save nire0510/7b831a99dd0db7ae79af to your computer and use it in GitHub Desktop.
ES6/2015 class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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