Skip to content

Instantly share code, notes, and snippets.

@iamdtang

iamdtang/main.js Secret

Last active August 30, 2024 01:32
Show Gist options
  • Save iamdtang/7849cc0ced4c1db9e6057f0f291e891d to your computer and use it in GitHub Desktop.
Save iamdtang/7849cc0ced4c1db9e6057f0f291e891d to your computer and use it in GitHub Desktop.
Classes and objects
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