Last active
September 10, 2015 21:38
-
-
Save ortense/9896f49a2fb8bfe5377f to your computer and use it in GitHub Desktop.
basic es6 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"; | |
/* <3 ES6 */ | |
class People{ | |
constructor(name, birthday){ | |
this.name = name; | |
this.birthday = birthday || new Date(); | |
} | |
sayName() { | |
console.log(`I'm ${this.name}`); | |
} | |
sayAge() { | |
var now = new Date(); | |
var age = Math.floor((now - this.birthday)/31536000000); | |
console.log(`I'm ${age} years old`); | |
} | |
} | |
let me = new People('Ortense', new Date(1988,2,1)); | |
me.sayName(); | |
me.sayAge(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment