Making new types available outside a closure

I see a lot of plugins use the JavaScript module pattern, like so:
Code:
(function() {
  //plugin code goes here
})();
Unfortunately, if the plugin defines things like custom windows, scenes, or sprites, the definitions are locked up in the anonymous scope in the original plugin, so nobody else can access them.

Is there a standard way to make those definitions available to other plugins without rewriting the whole thing to use a different pattern? I've found workarounds and hacks, but I'd prefer a method that's generally accepted, if one exists.
Some options:
  1. If it doesn't have to be global itself, define it on an existing global object, e.g. (both approaches valid):
    Code:
    var someGlobalObject = {};  // this is global
    (function() {
      someGlobalObject.myVar = "cake";  // property of a global object
    })();
    Code:
    var author = {};  // author namespace ("everything by me")
    author.pluginName = {};  // plugin namespace ("everything for this plugin")
    (function($) {  // label first IIFE argument as $ because it's a nice, short name
      $.myVar = "cake";
    })(author.pluginName);  // pass namespace as first argument of IIFE
  2. Explicitly define it on the global object (window in this case):
    Code:
    window.myVar = "cake";
  3. Implicitly define it on the global object by omitting the var/let keyword:
    Code:
    myVar = "cake";
  4. Define the globals outside of the IIFE:
    Code:
    var myVar = "cake";
    (function() {
      myVar.whatever = ...
    })();
For custom scenes/windows I'd go for case 2 (explicitly define as a property of the global object). No idea what you would classify as a "workaround" or "hack", though. 😅
My "at least it works" hacky solution was to grab the
Code:
function newTypeName() {
  this.initialize.apply(this, arguments);
}
declaration of each new type and move them up to the top of the file, outside the closure. I consider it hacky because it looks very weird, and I can't find any precedent for doing things that way.
Ah, yea, so case 4 from my suggestions. I agree, if there is a block limiting the scope of some of the plugin's content, I'd expect all the content to be inside such a block. (I do tend to define my namespaces outside the main IIFE, so I can pass them in as arguments, but I view them as elements of the underlying structure rather than strictly a part of the "plugin content".)

Just in case, to clarify, case 2 applied to your example could look like this:
Code:
(function() {
  window.newTypeName = function() {
    this.initialize.apply(this, arguments);
  };
  newTypeName.prototype = Object.create(parentTypeName.prototype);
  newTypeName.prototype.constructor = newTypeName;
  // etc
})();
@caethyril Yeah, that is basically what I do :

Spoiler
Code:
  (function($) {                                                                     // {

  // +=================================================|          Spriteset_VisualNovel |
  // | [Plugin] Spriteset_VisualNovel
  // +==================================================================================+

    function Spriteset_VisualNovel () {
      this.initialize.apply(this, arguments);
    }

    Spriteset_VisualNovel.prototype = Object.create(Spriteset_Map.prototype);
    Spriteset_VisualNovel.prototype.constructor = Spriteset_VisualNovel;

    // Reduce code line-length
    $ = $['Spriteset_VisualNovel'] = Spriteset_VisualNovel;

    // Code Here ...

  })(window);                                                                        // }

If I am going to be creating aliases and such I plop those into plugin specific, publicly accessible variables.

Spoiler
Code:
  (function($) {                                                                     // {

  // +=================================================|       Window_EnemyVisualSelect |
  // | [Plugin] Window_EnemyVisualSelect
  // +==================================================================================+

    // ossWindow is equal to Ossra.Plugin.[PluginName].Window
    var $win = setNamespace(ossWindow, 'Window_EnemyVisualSelect');
    // ... becomes Ossra.Plugin.[PluginName].Window.Window_EnemyVisualSelect

  // ALIAS -----------------------------------------------------------------------------+
  // | [Method] updateRefresh
  // +----------------------------------------------------------------------------------+

    $win.updateRefresh = $.prototype.updateRefresh;

    $.prototype.updateRefresh = function() {

      this.updateFontColor();

      $win.updateRefresh.call(this);

    }; // Window_EnemyVisualSelect << updateRefresh

  })(Window_EnemyVisualSelect);                                                      // }

Original thread: https://forums.rpgmakerweb.com/threads/making-new-types-available-outside-a-closure.115932/