Created
December 19, 2009 12:41
-
-
Save ELLIOTTCABLE/260067 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
// This does pretty much the thing that Node.js’s `require()` does. In this | |
// example, ‘exports is undefined’ never gets printed. This is as expected. | |
var wrapper = eval("var __wrap__ = function (exports) {" + '\n' + | |
"(function () {" + '\n' + | |
" if (typeof exports === 'undefined') { alert('exports is undefined' + '\\n') };" + '\n' + | |
" if (typeof exports === 'undefined') { exports = {} };" + '\n' + | |
"})()" + '\n' + | |
"}; __wrap__;", ''); | |
var exports_obj = new(Object); | |
wrapper.apply(exports_obj, [exports_obj]); |
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
// This does pretty much the thing that Node.js’s `require()` does. In this | |
// example (notice the `var` keyword on line 7), ‘exports is undefined’ gets | |
// printed. This makes no sense, because it very definitely *is* defined. | |
var wrapper = eval("var __wrap__ = function (exports) {" + '\n' + | |
"(function () {" + '\n' + | |
" if (typeof exports === 'undefined') { alert('exports is undefined' + '\\n') };" + '\n' + | |
" if (typeof exports === 'undefined') { var exports = {} };" + '\n' + | |
"})()" + '\n' + | |
"}; __wrap__;", ''); | |
var exports_obj = new(Object); | |
wrapper.apply(exports_obj, [exports_obj]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment