Skip to content

Instantly share code, notes, and snippets.

@WebReflection
Created October 5, 2011 08:30
Show Gist options
  • Save WebReflection/1263932 to your computer and use it in GitHub Desktop.
Save WebReflection/1263932 to your computer and use it in GitHub Desktop.
implicit require
var module = (function create(
namespace, handler, module, Proxy
) {
// ------------------------------------
// (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], Proxy);
return handler[name];
} else {
return module[name];
}
}
});
}("", {}, global, global.Proxy || require("node-proxy")));
@jdalton
Copy link

jdalton commented Oct 6, 2011

Hawt sauce

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment