The way I implement inheritance in JavaScript is shown in the example below. I am trying to call from the child class a method of the parent class. I have seen many examples online, that add the parent method to the prototype, and the use the call or apply function (but my implementation is not doing that). Is there a way to make this type of call?
function classM() //parent class
{
this.myName = function()
{
console.log('parent');
}
}
function classEM ()
{
classM.call(this);
this.myName = function()
{
console.log('child');
//HOW DO I CALL myName() of the parent class?
}
}
classEM.prototype = Object.create(classM.prototype);
classEM.prototype.constructor = classEM;
var rm = new classEM();
rm.myName(); //should print child and then parent
classM, soObject.create(classM.prototype)returns an object with nomyNamemethod. When you doclassM.call(this), the object gets the method, but then you overwrite it, so no, you can't call it.myNamemethods, why not create a new instance ofclassMinsideclassEMand call the darn method ?