A module pattern for nearly every occasion.
This gist is a fork of work by `millermedeiros <https://gist.github.com/1251668>`_ which is, in turn, a fork of work by `rpflorence <https://gist.github.com/1198466>`_.
This is a module pattern for JavaScript modules that can be loaded in both Node.js and the browser. This module pattern will choose a method for loading dependencies based on the environment (require() vs window).
(function (context, define) {
"use strict";
define.call(
context,
'ModuleName',
[
'dependency1',
'dependency2/submodule'
],
function (dependency1, dependency2) {
// Return the module definition.
return {};
}
);
}(...)
The previous versions of this pattern had direct support for AMD style modules. This, however, proved problematic because it would often require modifying the source of a module to adjust the paths for dependencies.