I have the following code:
function Rune(){
this.subSpells = [];
}
function Modifier(){
this.type = "modifier";
}
Modifier.prototype = new Rune();
function RuneFactory(effect, inheritsFrom, initialValue){
var toReturn = function(){};
toReturn.prototype = new inheritsFrom();
toReturn.prototype.subSpells[effect] = initialValue;
return toReturn;
}
Duration = RuneFactory("duration", Modifier, 1);
Quicken = RuneFactory("quicken", Modifier, 1);
x = new Duration();
y = new Quicken();
Both x.subSpells.duration and x.subSpells.quicken equal 1. Same with y. I want x.subSpells.quicken and y.subSpells.duration to be undefined.
If I do the following for the Duration and Quicken definitions, I get the behaviour I want.
Duration = RuneFactory("duration", Rune, 1);
Quicken = RuneFactory("quicken", Rune, 1);
I think there is a problem with double inheritance. Can anyone tell me how to change my RuneFactory code such that it works with double inheritance and/or explain what's breaking? If at all possible, I would like to avoid using a framework.
Thank you!