Created
November 20, 2012 21:19
-
-
Save hshoff/4121217 to your computer and use it in GitHub Desktop.
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
// new module1.js | |
(function() { | |
console.log('module1'); | |
// return a function that logs it's | |
// arguments when invoked | |
return function(){ | |
console.log(arguments); | |
}; | |
})() | |
// new production.js | |
// unminified problem for readability | |
(function() { | |
console.log('module1'); | |
// return a function that logs it's | |
// arguments when invoked | |
return function(){ | |
console.log(arguments); | |
}; | |
})()(function() { | |
console.log('module2'); | |
})(); | |
// => module1 | |
// => [function() { | |
// console.log('module2'); | |
// }] | |
// => TypeError: undefined is not a function | |
// the first step is to invoke the first module | |
(function(){console.log('module1');return function(){console.log(arguments)};})() | |
// => module1 | |
// then it invokes the return value | |
// with module2 as arguments | |
(function(){ console.log(arguments) })(function() {console.log('module2');}); | |
// => [function() { | |
// console.log('module2'); | |
// }] | |
// then it tries to invoke the return value. | |
// console.log returns undefined so: | |
(undefined)(); | |
// => TypeError: undefined is not a function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment