Skip to content

Instantly share code, notes, and snippets.

@getify
Created February 16, 2010 21:20
Show Gist options
  • Save getify/305934 to your computer and use it in GitHub Desktop.
Save getify/305934 to your computer and use it in GitHub Desktop.
var Require = function() {
function NativeRequire(module) {
var source;
// read source from file
if (!FS) {
source = imports.FSREAD("modules/fs.js");
FS = Function.apply(Function,imports_names.concat([source])).apply(Function,imports_funcs);
}
if (module !== "fs") {
source = FS.read("modules/"+module+".js");
return Function.apply(Function,imports_names.concat([source])).apply(Function,imports_funcs);
}
return FS;
}
function SubClass(){}
NativeRequire.prototype = SubClass.prototype;
NativeRequire.prototype.constructor = Require;
return NativeRequire;
};
var myrequire = new Require();
require("something"); // works
console.log(myrequire.constructor === Require);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment