If I'm writing a JavaScript module for the browser, I'd assign it to window
:
window.myModule = function(){ };
For node, I'd assign it to module.exports
:
module.exports = function(){ };
What's the cleanest syntax for handling all scenarios? My current code is pretty gross:
(function(container, containerKey){
container[containerKey] = function(){ };
})(module ? module : window, module ? 'exports' : 'myModule');
I've seen examples like this, but the export is an object.
This answer is close, but I want to export directly to module (I don't want the extra qualifier).