I find this code repetitive because it repeatedly uses Child.prototype
:
function Parent(a)
{
this.a = a;
}
function Child(a, b)
{
Parent.call(this, a);
this.b = b;
}
Child.prototype = Object.create(Parent.prototype);
Child.prototype.constructor = Child;
Child.prototype.childValue = 456;
Child.prototype.anotherChildValue = 457;
Child.prototype.yetAnotherValue = 458;
Child.prototype.IHateToWriteChildPrototypeEachTime = 459;
// ...and so on
I prefer a more concise way to add new members like this:
{
constructor: Child,
childValue: 456,
anotherChildValue: 457,
yetAnotherValue: 458,
ILoveThisSinceItsSoTerse: 459,
// ...and many more
}
Is there a simpler and more efficient method to achieve this without creating additional functions or reinventing existing solutions?