What does get mean in this ES6 class? How do I reference this function? How should I use it?
class Polygon {
constructor(height, width) {
or more simple way it just call the function without needing to user "()" just by typing the function name
the two above function are equal attention to person.fullName() and person.fullName
const person = {
firstName: 'Willem',
lastName: 'Veen',
fullName() {
return `${this.firstName} ${this.lastName}`;
}
}
console.log(person.fullName());
const person = {
firstName: 'Willem',
lastName: 'Veen',
get fullName() {
return `${this.firstName} ${this.lastName}`;
}
}
console.log(person.fullName);