This will now provide you with demoLib.someMethod() returning Something and demoLib.helloMethod('World') returning "Hello World". The final step to enable such a library is to add ltng:require to your components: <ltng:require scripts="{!Resource.demoLib} afterScriptLoaded="someMethodIfRequired" /> presuming you stored your JS in resources as demoLib.js. The Aura framework will make sure that the library is loaded once only, regardless how many components define it as dependency.

You need to be clearly communicating service names to other developers in your org. If someone has the idea to name a library the same as yours, things will break. Good practice is to check if your library and function is available: if (window.demoLib && window.demoLib.someMethod) {...}

Fat arrow functions () => {...} are not supported in legacy browsers, so you need the slightly more verbose function(){...} (beware the this keyword behaves different then).

About Me

Contact

Disclaimer

This site is in no way affiliated, endorsed, sanctioned,
supported, nor enlightened by my current or previous employers.
I may be an employee, but the opinions, theories, facts, etc.
presented here are my own and are in now way given in any official
capacity. In short, these are my words and this is my site, not
my current or former employers' - and don't even begin to think otherwise.