Skip to content

Instantly share code, notes, and snippets.

@silentrob
Created February 3, 2010 22:21
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 silentrob/294098 to your computer and use it in GitHub Desktop.
Save silentrob/294098 to your computer and use it in GitHub Desktop.
Module.prototype.load = function (filename) {
var self = this;
this.filename = filename;
function require (url) {
return loadModule(url, self);
}
var x = system.filesystem.get(this.filename);
var contents = x.contents;
var wrapper = "(function (exports, require, module, __filename, __dirname) { "
+ contents
+ "\n});";
try {
var compiledWrapper = eval(wrapper);
compiledWrapper.apply(self.exports, [self.exports, require, self]);
} catch (e) {
throw new Error("Something bad happened");
return;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment