Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The code you provided is an example of the <a href="http://www.adequatelygood.com/JavaScript-Module-Pattern-In-Depth.html" rel="noreferrer" title="JavaScript Module Pattern: In-Depth">module pattern</a>. In particular it's an example of <a href="http://www.adequatelygood.com/JavaScript-Module-Pattern-In-Depth.html#loose_augmentation" rel="noreferrer" title="JavaScript Module Pattern: In-Depth">loose augmentation</a> of the module pattern.</p> <p>The module pattern is basically just an <a href="http://benalman.com/news/2010/11/immediately-invoked-function-expression/" rel="noreferrer" title="Ben Alman &raquo; Immediately-Invoked Function Expression (IIFE)">immediately invoked function expression (IIFE)</a> which returns an object. For example:</p> <pre><code>// file 1 var MODULE = (function () { var my = {}, privateVariable = 1; function privateMethod() { // ... } my.moduleProperty = 1; my.moduleMethod = function () { // ... }; return my; }()); </code></pre> <p>Augmentation allows you to split a module into parts. Each part can reside in it's own file. For example we can augment the above module as follows:</p> <pre><code>// file 2 var MODULE = (function (my) { my.anotherMethod = function () { // added method... }; return my; }(MODULE)); </code></pre> <p>However in this pattern of augmentation <code>file 1</code> must be loaded before <code>file 2</code> or else you'll get an error. Loose augmentation allows you to load files in any order.</p> <pre><code>var MODULE = (function (my) { // add capabilities... return my; }(MODULE || {})); </code></pre> <p>In the above example the module <code>MODULE</code> may be split over multiple files which can be loaded in any order. The expression <code>MODULE || {}</code> evaluates to <code>MODULE</code> if it exists. Otherwise it evaluates to <code>{}</code>.</p> <p>Hence for the first file that's loaded the expression will evaluate to <code>{}</code> because <code>MODULE</code> would initially be <code>undefined</code>. In subsequent files the expression would evaluate to <code>MODULE</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload