-
-
Save iamdtang/7849cc0ced4c1db9e6057f0f291e891d to your computer and use it in GitHub Desktop.
Classes and objects
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
class Person { | |
constructor(firstName, lastName) { | |
this.firstName = firstName; | |
this.lastName = lastName; | |
} | |
get fullName() { | |
return `${this.firstName} ${this.lastName}`; | |
} | |
introduce() { | |
return `Hi, my name is ${this.fullName}.`; | |
} | |
} | |
const david = new Person('David', 'Tang'); | |
david.firstName; | |
david.introduce(); | |
const david2 = { | |
firstName: 'David', | |
lastName: 'Tang', | |
get fullName() { | |
return `${this.firstName} ${this.lastName}`; | |
}, | |
introduce() { | |
return `Hi, my name is ${this.fullName}.`; | |
} | |
}; | |
david2.introduce(); | |
class Student extends Person { | |
study() { | |
return `${this.fullName} has notifications turned off.` | |
} | |
} | |
const shreesh = new Student('Shreesh', 'Yadav'); | |
shreesh.study(); | |
shreesh.introduce(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment