I'm writing tests for some small JavaScript libraries. In one small library I have a few "classes":
// lib/ChordMaker.js
var wheel = require("./wheel");
var Maker = function (options) {
// ...
};
Maker.prototype.compute = function () {
return wheel.modify(this.options.base, this.options.angle);
};
module.exports = Maker;
You can see the problem there when I am using the wheel
dependency without injecting it. But "wheel" is an internal class that doesn't need to be exposed to the lib user--I don't want to force them to know what wheel is:
var maker = new ChordMaker(wheel); // wait wtf is wheel
So how do you inject internal dependencies without forcing the lib user to pass all of them in?
One suggested solution:
And then only use
options.wheel
inside the ChordMaker object. So then an end user would say:Is that the best solution?