Answer the question
In order to leave comments, you need to log in
Do I need to implement multiple inheritance?
In my project for inheritance, I implemented the function
function inherit(child, parent, proto, descriptor) {
if (!descriptor)
descriptor = {};
descriptor['base'] = {
value: parent,
enumerable: false,
writable: false
};
child.prototype = Object.create(parent.prototype);
child.prototype.constructor = child;
var names = proto ? Object.getOwnPropertyNames(proto) : [];
for (var i in names) {
var name = names[i];
descriptor[name] = Object.getOwnPropertyDescriptor(proto, name);
}
Object.defineProperties(child.prototype, descriptor);
child.descriptor = descriptor;
return child;
}
function ext(target, extension) {
if (target.prototype)
target = target.prototype;
for (var key in extension)
if (!(key in target))
Object.defineProperty(target, key, {
value: extension[key],
enumerable: false
});
}
Answer the question
In order to leave comments, you need to log in
Multiple inheritance leads to a lot of the same problems :)
Better attach the mechanism of mixins, and even better - component-oriented programming.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question