Prototype confusion in Javascript !!
Anonymous
function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
// Greeting
Person.prototype.greeting = function(){
return `Hello there ${this.firstName} ${this.lastName}`;
}
// Customer constructor
function Customer(firstName, lastName, phone, membership) {
Person.call(this, firstName, lastName);
this.phone = phone;
this.membership = membership;
}
// Inherit the Person prototype methods
Customer.prototype = Person;
let detail1 = new Customer("hom", "kom", 989, "l");
detail1.greeting()// it is producing error that greeting is not a function
Why when I am running detail1.greeting() is producing error even though I have set the prototype.