Accessing Helper Function Library Throughout the Whole Project

Hey all,

Question about a function library that can be accessed through the whole project. What is the best way to do this? Ideally I’d want a script called “helper.js”, that I can drop in any project and access easily in other scripts. Helper.js would be something like this:

function getRandomInt(max) {
  return Math.floor(Math.random() * max);

What setup do yall use for generic functions in a project?

Thanks in advance,

As long as it’s in the global scope (under window for example), it can be accessed anywhere after it has been defined

You can see an example here: PlayCanvas | HTML5 Game Engine

1 Like

Is there a list of global objects somewhere like window? I know thats a general web dev question but I’m just not sure where the best place to drop this is. Curious what other people’s work flow is for this.

window is generally your top most scope and is basically global scope

I tend to do something like this:

(function() {
  var tempVar = 0;
  function foobar() { };
  window.foobar = foobar; 

This reduces pollution of the global scope with temp variables because it is in a function scope and only expose the function to the window scope