Created
February 16, 2010 21:20
-
-
Save getify/305934 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
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