Skip to content

Instantly share code, notes, and snippets.

@ortense
Last active September 10, 2015 21:38
Show Gist options
  • Save ortense/9896f49a2fb8bfe5377f to your computer and use it in GitHub Desktop.
Save ortense/9896f49a2fb8bfe5377f to your computer and use it in GitHub Desktop.
basic es6 class
"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