I have created a class/library. and I used the new class syntax with a constructor and its methods, now what? what should I put in it for using that in a external JS file?
I have something like this
class LoadBalancer {
constructor() {/*...*/}
method1(...bla) {/*...*/}
}
Should I put at the top a use strict
?
'use strict';
Maybe put my class inside a Self-Executing Anonymous Functions? or use a export
with my class name?
I have seen many .js files that have a syntax like this:
(function (root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define("EventBus", [], factory);
else if(typeof exports === 'object')
exports["EventBus"] = factory();
else
root["EventBus"] = factory();
})(this, function() { /*....
their functions and libraries declaration goes here
.....*/
return whatEverNewFunc();
});
But I do not know what it means and what happens if you just do not use them or what are the advantages, what if I just place my class LoadBalancer {/*...*/}
in a loadBalancer.js file, and thats it.