let's suppose we have an object Person as follows:
function Person(name){
this.name = name;
this.greeting = function(){
alert("Hi I'm " + this.name);
}
}
and its child
function Teacher(name, subject){
Person.call(this, name);
this.subject = subject;
Teacher.prototype = Object.create(Person.prototype);
}
I tried to override greeting method as follows:
Teacher.prototype.greeting = function(){
alert("Hello my name is " + this.name + " and I teach " + this.subject);
}
but teacher1.greeting() invokes Person's method and not Teacher's one, as you can see here:
- Where's the mistake?

greetingmethod onPerson.prototype, not inside the constructor, and b) move theTeacher.prototype = Object.create(Person.prototype)outside of theTeacherconstructor.