Last active
October 5, 2015 01:15
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(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... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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