Skip to content

Instantly share code, notes, and snippets.

@ryantenney
Forked from WebReflection/module.js
Created October 6, 2011 23:24
Show Gist options
  • Save ryantenney/1268987 to your computer and use it in GitHub Desktop.
Save ryantenney/1268987 to your computer and use it in GitHub Desktop.
implicit require
var module = (function create(
namespace, handler, module
) {
// ------------------------------------
// (C) WebReflection - MitStyle License
// ------------------------------------
// @dependency npm install node-proxy
// ------------------------------------
// var sys = module.sys;
// sys.print("it works!");
// var yet = sys.nonexisting.yet;
// yet.doStuff();
// ------------------------------------
return Proxy.create({
get: function (receiver, name) {
if (!module.hasOwnProperty(name)) {
var key = namespace ?
namespace + "/" + name :
name
;
module[name] = require(key);
handler[name] = create(key, {}, module[name]);
return handler[name];
} else {
return module[name];
}
}
});
}("", {}, global));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment