Created
January 31, 2010 13:12
-
-
Save tim-smart/291063 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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; | |
}); | |
}; |
This file contains hidden or 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
exports.MyObj = { | |
hi : "there" | |
} |
This file contains hidden or 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 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