title: Create a global function in JavaScript
body: <p>I'm trying to create a global function where I can use it anywhere inside a <code>.js</code> file.</p>
  
  <p>We have more than 50 javascript files joined together and inside each files I want to be able to use this library anywhere.</p>
  
  <p>Localized.js</p>
  
  <pre><code>(function (root, factory) {
      if (typeof define === 'function' &amp;&amp; define.amd) {
          // AMD. Register as an anonymous module.
          define(factory);
      } else if (typeof exports === 'object') {
          // Node. Does not work with strict CommonJS, but
          // only CommonJS-like enviroments that support module.exports,
          // like Node.
          module.exports = factory();
      } else {
          // Browser globals (root is window)
          if (typeof Localized !== 'undefined') {
              throw 'Localized" already in use';
          }
  
          root.Localized = factory();
      }
  }(this, function () {
  
    var _strings,
        _readyCallback,
        _isReady = false,
        _requestedStrings = false;
  
    function ready( data ) {
       _readyCallback = _readyCallback || function(){};
  
      function domReady() {
        // If the DOM isn't ready yet, repeat when it is
        if ( document.readyState !== "complete" ) {
          document.onreadystatechange = domReady;
          return;
        }
        document.onreadystatechange = null;
        _strings = data;
        _isReady = true;
        _readyCallback();
      }
  
      domReady();
    }
  
    // Get the current lang from the document's HTML element, which the
    // server set when the page was first rendered. This saves us having
    // to pass extra locale info around on the URL.
    function getCurrentLang() {
      var html = document.querySelector( "html" );
      return html &amp;&amp; html.lang ? html.lang : "en-US";
    }
  
    var Localized = {
      get: function( key ) {
        if ( !_strings ) {
          console.error( "[goggles.webmaker.org] Error: string catalog not found." );
          return "";
        }
        return ( _strings[ key ] || "" );
      },
  
      getCurrentLang: getCurrentLang,
  
      // Localized strings are ready
      ready: function( cb ) {
        if ( !_requestedStrings ) {
          _requestedStrings = true;
          _readyCallback = cb;
  
          function onload( data ) {
            ready( data );
          }
          onload.error = console.log;
  
          var xhr = new XMLHttpRequest();
          xhr.open('GET', '/strings/' + getCurrentLang() + '?bust=' + Date.now(), false);
          xhr.send(null);
          if (xhr.status !== 200) {
            err = new Error(id + ' HTTP status: ' + status);
            err.xhr = xhr;
            onload.error(err);
            return;
          }
          onload(JSON.parse(xhr.responseText));
        };
        if ( _isReady ) {
          _readyCallback();
        }
      },
  
      isReady: function() {
        return !!_isReady;
      }
    };
    return Localized;
  }));
  </code></pre>
  
  <p>So I want to be able to go into any of the <strong>50</strong> files and do <code>Localized.get("something");</code>
  But then I don't even have the <code>Localized</code> object available in the <strong>web console</strong>. For example if you have <code>jQuery</code> you can do <code>$</code> in the web console and you can do anything there.</p>