Hi all, in the following code I have a Parent and Child class. I’m trying to model a constructor/class type view. I inherit the parents methods by using “call”, but once this is done, any of the child methods that are named the same are overrided by the parent!
You can just copy and paste the below code to run it.
Any help would be greatly appreciated.
[code]
function ParentTest(el){
function initialize(obj, el){
obj.el = el;
alert(‘Valid initial…’);
}
this.publicMethod = function() {
alert(‘I am public!’);
privateMethod();
}
function privateMethod(){
alert(‘I am private!’);
}
this.overrideMe = function() {
alert(‘I am in ParentTest!’);
}
initialize(this, el);
}
function ChildTest(el, name){
var test = ‘private var’;
function initialize(obj, el, name){
ParentTest.call(obj, el);
obj.name = name;
obj.overrideMe();
}
this.showTest = function() {
alert(test);
}
this.show = function() {
alert(‘My el is: ‘ + this.el + ‘ and my name is: ‘ + this.name);
}
// This gets overrode by the parent.
this.overrideMe = function() {
alert(‘I am in ChildTest!’);
}
initialize(this, el, name);
}
var test= new ChildTest(‘el4’, ‘myName’);