I have two very simple prototypes in Javascript; however, when attempting to ensure one prototype inherits from the other, I am seeing behavior I don't understand. I am following Mozilla Developer Network's article on inheritance:
const Model = function (data) {
this.doSomething(data);
};
Model.prototype.doSomething = function (data) {
console.log("something");
};
// Second "inheriting" model
const Word = function (data) {
Model.call(this, data);
};
// Example use:
let word = new Word({ literal: "duck" });
When my code executes the Model
prototype's constructor, I get an error I do not understand in this context:
this.doSomething is not a function.
As this is a relatively simple use case of inheritance, it leads me to believe I am missing something, entirely, about the prototype chain.
Is it not possible to call a function defined on an iherited prototype from the inherited prototype's constructor?