See this code of prototypal inheritance:
var Person = function() {
this.canTalk = true;
};
Person.prototype.greet = function() {
if (this.canTalk) {
console.log('Hi, I am ' + this.name);
}
};
var Employee = function(name, title) {
Person.call(this);
this.name = name;
this.title = title;
};
Employee.prototype = Object.create(Person.prototype);
// Note: there's no difference, when I comment out the following line
Employee.prototype.constructor = Employee;
Employee.prototype.greet = function() {
if (this.canTalk) {
console.log('Hi, I am ' + this.name + ', the ' + this.title);
}
};
var bob = new Employee('Bob', 'Builder');
bob.greet();
I do get the same result (console output) even if I comment out the line
Employee.prototype.constructor = Employee;
Then what is worth of equalizing the function prototype constructor to function itself. I am a newbie in JS. Also if it effects in long run. How? I do not want any workarounds.