thanks to help from stackoverflow posters I have set up some oop javascript. However, I have hit another snag.
I have two different classes with the same inheritance. They then both have a function named the same, but doing different things. The trouble is, if ClassB is defined last, then even when I have a ClassA object, and write classAInstance.MyFunction(); it returns 2, ie ClassB’s function of the same name.
BaseClass = function(){
...init some stuff...
};
ClassA = function(){
BaseClass.call(this);
...init some stuff...
};
ClassA.prototype = BaseClass.prototype; // innherit
ClassA.prototype.MyFunction(){
return 1;
};
ClassB = function(){
BaseClass.call(this);
...init some stuff...
};
ClassB.prototype = BaseClass.prototype; // innherit
ClassB.prototype.MyFunction(){
return 2;
}
The reason why is because both ClassA and ClassB’s prototype is pointing to the same object. I’m not sure what your use case is for this but it would be just as well to have the prototype be an instance.