Just call A
constructor with this
function B(aOptions, bOptions) {
A.call(this, aOptions);
// do stuff with bOptions here...
}
Now to setup the prototype
B.prototype = Object.create(A.prototype, {
constructor: {
value: B
}
});
Now B will have the prototype methods from A.
Any new methods added to B's prototype will not be available to A's prototype
There's a couple other tweaks that can make your life easier too.
function A(options) {
// make `new` optional
if (!(this instanceof A)) {
return new A(options);
}
// do stuff with options here...
}
And do the same for B
function B(aOptions, bOptions) {
// make `new` optional
if (!(this instanceof B)) {
return new B(aOptions, bOptions);
}
// call parent constructor
A.call(this, aOptions);
// do stuff with bOptions here...
}
Now you can call A(options)
or new A(options)
to get the same result.
Same with B, B(aOptions, bOptions)
or new B(aOptions, bOptions)
will get the same result.