Skip to content

Instantly share code, notes, and snippets.

@al-the-x
Last active October 5, 2015 01:15
Show Gist options
  • Save al-the-x/584e3082316c7aa8f4a0 to your computer and use it in GitHub Desktop.
Save al-the-x/584e3082316c7aa8f4a0 to your computer and use it in GitHub Desktop.
Explaining the IIFE pattern _and_ `require` at the same time to TIY-Durham/2015-FALL-FEE
;(function(globals){ // That IIFE though...
// In Node JS: module.exports.hello = hello;
// In Browser: window.hello = hello;
globals.hello = hello;
// In Node JS: module.exports.hello();
// In Browser: window.hello();
globals.hello();
function hello(){
console.log('Hello from main.js!');
}
})(module && module.exports || window || this);
// Now we know a little more...
var test = require('mocha').it,
expect = require('chai').expect,
main = require('./main.js');
main.hello(); // Just a sanity check...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment