I am working on my first Node.js project and I have come to an OOP problem that I am not sure how solve in Node.js.
I have a module A:
module.exports = A;
function A() {
}
A.prototype.method = function() { return "A";};
//other methods...
and couple other modules (lets say B and C) that implement same "interface" as A.
Now, I have module X:
module.exports = X;
function X(impl) {
//choose A, B, or C based on value of impl
}
So the question is, how do I implement X in order to be able to do:
var X = require("x");
var impl = new X("A");
impl.method(); //returns "A"
I believe prototype and __proto__ will be involved?
Edit: What I am trying to achieve is load implementation A, B or C, based on some string value (ENV variable) through standartized interface new X() and then access methods of A(B,C...) through that instance of X.