I want to know, in javascript when using the class keyword where are the prototype methods stored? For instance in the below code I have declared a Person class containing a method getInfo, When I try to do Person.prototype it outputs an empty object. But I've also read that classes are just syntactic sugar for constructor functions. But now I guess there's still some distinction between them, So can someone please explain what is it?
class Person {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
getInfo() {
console.log(`First Name: ${this.firstName} \nLast Name: ${this.lastName}`);
}
}
console.log(Person.prototype);
As far as I know if the same had to done using a Constructor function, Then it would be done something like the below code snippet.
function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
Person.prototype.getInfo = function() {
console.log(`First Name: ${this.firstName} \n ${this.lastName}`);
}
console.log(Person.prototype);