I have a javascript object PathDiagramElement that has few prototype members. There is a PassiveElement object whose prototype is PathDiagramElement.
Also PassiveElement, has a lot of prototype members of its own.
var PathDiagramElement = function(){};
PathDiagramElement.prototype = {
myself : "Parent",
getTest : function() {
return this.myself + " function";
}
};
var PassiveElement = function() {};
PassiveElement.prototype = new PathDiagramElement();
PassiveElement.prototype = {
myself : "Child",
getTestChild : function() {
return this.myself+ " function";
}
};
var p = new PassiveElement();
alert(p.getTestChild());
alert(p.getTest());
p.getTestChild() works fine. But p.getTest() throws undefined is not a function error.
But if I change
PassiveElement.prototype = {
myself : "Child",
getTestChild : function() {
return this.myself+ " function";
}
};
to
PassiveElement.prototype.myself = "Child";
PassiveElement.prototype.getTestChild = function() {
return this.myself+ " function";
}
everything works fine.
How do I define an object that has multiple prototype members of its own as well as has to use a prototype of another object?
Thanks in advance.