Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
bclinkinbeard committed Jan 9, 2014
1 parent b518197 commit 6e97514
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion posts/how-browserify-works/index.html
Expand Up @@ -105,7 +105,7 @@ <h3><a name="generated-closure" class="anchor" href="#generated-closure"><span c
<h2><a name="the-cache" class="anchor" href="#the-cache"><span class="header-link"></span></a>The cache</h2>
<p>The second argument provided to the IIFE is the cache of modules defined in any bundles that were loaded before ours. This is almost always going to be an empty <code>{}</code>, so we&#39;re actually going to skip it here. Just know that it&#39;s basically another module map, defined elsewhere, that might get passed into your bundle when it starts up.</p>
<h2><a name="entry-modules" class="anchor" href="#entry-modules"><span class="header-link"></span></a>Entry modules</h2>
<p>The third and final argument passed to the bundle IIFE is an array of module ids that will serve as the starting point for building our dependency graph. In our case, remember, <code>entry.js</code> has been given an id of <code>2</code>. Therefore the third argument is <code>[2]</code>. It is an array because you can specify multiple entry files, but that isn&#39;t very common.</p>
<p>The third and final argument passed to the bundle IIFE is an array of module ids that will serve as the starting point for building our dependency graph. In our case, remember, <code>entry.js</code> has been given an id of <code>2</code>. Therefore the third argument is <code>[2]</code>. It is an array because you can specify multiple entry files, which is apparently common for running tests, but not something I have seen a lot of.</p>
<h2><a name="making-it-all-work" class="anchor" href="#making-it-all-work"><span class="header-link"></span></a>Making it all work</h2>
<p>Now that we know what is being passed, let&#39;s talk about what the F in the IIFE actually does. This function also comes from the browser-pack project. Specifically, the <a href="https://github.com/substack/browser-pack/blob/d29fddc8a9207d5f967664935073b50971aff708/prelude.js">prelude.js file</a>. I&#39;d encourage you to click through and read the file itself (it&#39;s pretty well commented), but it&#39;s actually even simpler than it looks.</p>
<p>Basically, each entry module id is passed into a function where it is looked for in the cache. If it is found, the module&#39;s <code>exports</code> property is returned, fulfilling the dependency. If the id is not found in the cache then our own module map is checked.</p>
Expand Down

0 comments on commit 6e97514

Please sign in to comment.