const personPrototype = {
greet() {
console.log(`hello, my name is ${this.name}!`);
}
}
function Person(name) {
this.name = name;
}
Person.prototype = personPrototype;
Person.prototype.constructor = Person;
In the above code, PersonPrototype is set to Person.prototype, Here what is personPrototype? If its a variable, it should be defined using let right?
How is the code accepting this? plz help me in detailed understanding.
personPrototype is defined on the first line with const. It’s const not let since it won’t change. It’s an object with a function that gets assigned to Person.prototype.