I want to create a child JS object which passes arguments back to parent constructor and will be able to override parent methods.
I've done the task by a hack, please my fiddle http://jsfiddle.net/glebv/kbvmzg63/3/
Parent constructor:
var Parent = function (name) {
this.meth1 = function () {
console.log("Parent meth1 ", name);
};
this.meth2 = function() {
console.log('Parent meth2 ', name);
};
return this;
}
Please pay attention on "name" argument which is used in the methods.
Child constructor:
var Child = function (name) {
var child = new Parent(name);
for (var property in child) {
this[property] = child[property];
}
this.meth1 = function () {
console.log("Child ", name);
};
return this;
}
As you see, it's not classical inheritance, it's copy-past methods from the parent to the child. I guess there's more powerful method via prototype inheritance. There's simple acceptance criteria: 1) it should work
childObj = new Child("bla");
childObj.meth1(); //Child bla
childObj.meth2(); //Parent meth2 bla
2) Parent constructor is not changeable because it belongs to external lib.
I've test different solutions but it didn't solve my task. I will appreciate for your suggestions.
UPD
The task is solved, there's solution jsfiddle.net/glebv/kbvmzg63/5