I have the following node module:
var _ = require('lodash');
function Config(configType, configDir) {
this.configType = configType;
this.configDir = configDir;
};
Config.prototype.read = function() { // read file to buffer };
Config.prototype.modify = function() { // modify buffer };
Config.prototype.write = function() { this.modify(); // now write };
var base = _.curry(Config);
module.exports.A = base('A');
module.exports.B = base('B');
module.exports.C = base('C');
// In some other file
var config = require('config');
var a = new config.A('a/dir');
var b = new config.B('b/dir');
var c = new config.C('c/dir');
The problem is that with ConfigC, I don't actually want to call the modify method. I have thought about doing a conditional in the write function based upon configType but ideally I'd like ConfigC to just 'know' what to do, either by overriding the write function or some other javascript-ism that I'm not aware of.
Does anyone know of an elegant solution to this problem?