Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Classes in ES6
- // Classes in ES6 are not hoisted. Also, you can only add methods to classes, not properties.
- class Person {
- // Every class must have a constructor
- constructor(name, birthYear, job) {
- this.name = name;
- this.birthYear = birthYear;
- this.job = job;
- } // no comma here, oddly enough.
- //Methods are added here
- calculateAge() {
- var age = new Date().getFullYear - this.birthYear;
- console.log(age);
- }
- // static class example
- static greetings() {
- console.log('Hey there!');
- }
- }
- const john6 = new Person ('John', 1990, 'teacher');
- Person.greetings(); //static class must be invoked.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement