Skip to content

Instantly share code, notes, and snippets.

@ELLIOTTCABLE
Created December 19, 2009 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ELLIOTTCABLE/260067 to your computer and use it in GitHub Desktop.
Save ELLIOTTCABLE/260067 to your computer and use it in GitHub Desktop.
// 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 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