Skip to content

Instantly share code, notes, and snippets.

@tim-smart
Created January 31, 2010 13:12
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 tim-smart/291063 to your computer and use it in GitHub Desktop.
Save tim-smart/291063 to your computer and use it in GitHub Desktop.
exports.AutoLoader = function() {};
AutoLoader.prototype.autoload = function(type, filePath, includeAsType) {
var obj = undefined;
if(includeAsType === undefined) includeAsType = true;
this.__defineGetter__(type, function(){
if(!obj){
obj = require(filePath);
if(includeAsType) obj = obj[type];
}
return obj;
});
};
exports.MyObj = {
hi : "there"
}
var paths = require("path"),
AutoLoader = require("./autoloader").AutoLoader;
var foo = new AutoLoader();
foo.autoload("MyObj", paths.join(__dirname, "myObj"));
sys.puts(foo.MyObj);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment