You can simply use Object.create
:
var operation =
{
A: 1,
B: 2,
C: 3
};
var operationImplA = Object.create(operation, {
D: {
value: 4
}
});
var operationImplB = Object.create(operationImplA, {
D: {
value: 5
}
});
Object.create
will create new object with prototype it's first argument and properties defined in the second argument.
This is the natural prototype-based inheritance in JavaScript.
Edit
If you want to add a method, add it like a property i.e.:
var operationImplA = Object.create(operation, {
M: {
value: function (a) {
console.log(a);
}
}
});
operationImplA.M('Some text...'); //'Some text...'