While I'm not huge into forcing OOP into a functional language, I'm struggling to understand what a peer of mine did to export modules from a Class. All I'm looking for is what to call this so I can continue to do research. From what I understand they were including some external SDK to be passed into an internal class which would inherit everything into the LibIncludes. This is suppose to allow all of the classes to inherit into the LibIncludes and LibIncludes inherits from Object. What I'm running into now is that anytime I try to call LibIncludes.Handlers; and execute a function included in Handlers I'm getting undefined. I can't figure out what pattern he applied to make this work and everything in ES6 shows an entirely different approach to exporting and importing between classes for inheritance. Any help would be greatly appreciated.
// index.js
const ExternalSdk = new SDK.Function();
const HandlerService = require('./hander/handler.js');
class LibIncludes {
static compose() {
const Handler = new HandlerSvc(ExternalSdk);
return {
Handler
};
}
}
module.exports = LibIncludes;
let function = LibIncludes.sdkFunciton;
// function should be invoked and return some object
Here's the solution I came up with for refactoring. It seems cleaner and without the static members:
// index.js
const ExternalSdk = new SDK.Function();
const HandlerService = require('./hander/handler.js');
module.exports = class LibIncludes {
constructor(handler) {
this.handler = new HandlerSvc(ExternalSdk);
}
}
// app.js
const lib = require('./index');
var getSomething = new lib();
console.log(getSomething.handler);
// function should be invoked and return some object