Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //ES6 Classes (syntactic sugar built upon protoypes)
- class Person {
- constructor(firstName, lastName, dob){
- this.firstName = firstName;
- this.lastName = lastName;
- this.birthday = new Date(dob);
- }
- greeting(){
- return `Hello there ${this.firstName} ${this.lastName}`;
- }
- calculateAge(){
- const diff = Date.now() - this.birthday.getTime();
- const ageDate = new Date(diff);
- return Math.abs(ageDate.getUTCFullYear() - 1970);
- }
- getsMarried(newLastName){
- this.lastName = newLastName;
- }
- static addNumbers(x, y){
- return x + y;
- }
- }
- const mary = new Person('Mary', 'Williams', '11-13-1980');
- mary.getsMarried('Thompson');
- console.log(mary);
- console.log(mary.greeting());
- console.log(mary.calculateAge());
- console.log(Person.addNumbers(1,2));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement