EDIT: I understand the purpose of Object.create() in general. But i need to know why it is used in the below code as it makes no difference at all.
I found the below code in this article. I can understand that fruits.call(this);
will essentially inherit the properties from fruits to any instance of apple that gets created. Then why do we need to do apple.prototype = Object.create(fruits.prototype);
Can anyone explain the purpose of this line? I tried executing the code without the that line and it still runs with no issues.
function fruits() {
this.name = 'fruit 1';
}
function apple() {
fruits.call(this);
}
apple.prototype = Object.create(fruits.prototype);
const app = new apple();
console.log(app.name);
// Output: fruit 1