Also, as is mentioned in an answer, you need to get rid of the `defer` or the function won't exist when you call it.
– CullyJun 25 '21 at 07:49
Or you could do `window.addEventListener('load', () => window.MyFunctions.out("Hello"))`
– CullyJun 25 '21 at 07:52
Does this answer your question? [Browserify - How to call function bundled in a file generated through browserify in browser](https://stackoverflow.com/questions/23296094/browserify-how-to-call-function-bundled-in-a-file-generated-through-browserify)
– CullyJun 25 '21 at 07:52
@Cully I would want to make this bundle redistributable in a way that the global namespace is not polluted.
– Tara SharmaJun 25 '21 at 08:07
@Cully I also don't want this function to run as soon as the page is loaded. How can It be called like a regular function?
– Tara SharmaJun 25 '21 at 08:09
You can run it whenever you want. You just can't run it before the script has loaded. That's why you wait for the load event. Or you could get rid of `defer`.
– CullyJun 25 '21 at 15:49
I did remove the defer attribute and tried calling the function. I'm still getting the same error.
– Tara SharmaJun 25 '21 at 16:21
@Cully Is there any way I can run this function without putting it in the global namespace?
– Tara SharmaJun 25 '21 at 17:07
Not that I know of. You could make it a library (someone else could include it in their bundle). Or just namespace everything you put on window (e.g. `window.MyLibrary.out`, `window.MyLibrary.doSomething`, etc.)
– CullyJun 25 '21 at 17:11