I wrote autoloader/autoinstaller that uses harmony proxy. Try to use 
:) https://github.com/nin-jin/node-jin#autoloader

четверг, 10 марта 2011 г., 21:31:28 UTC+4 пользователь Marcel Laverdet 
написал:
>
> I'm finding that the first 6-12 lines of most of my files with NodeJS are 
> just require()'s, and was thinking about ways to cut down on that. I feel 
> that in many applications it will make sense to use objects-of-functions 
> and constructor-functions as top level globals which can be used anywhere. 
> This is a pretty common practice in other languages and there seems to be 
> no parallel in CommonJS / NodeJS.
>
> So I wrote `autoload` which is in npm now:
> npm install autoload
> or:
> https://github.com/laverdet/node-autoload/
>
> You give it a root path to search and it will find any globals your 
> modules export and put a getter on the global object. When accessed the 
> getter will load the module which defines the global, and then overwrite 
> itself with the found value. You can also write your own hooks to search 
> for symbols which would allow you to detect symbols added to a common 
> project-specific namespace but distributed over many files (that is, 
> instead of using pure globals).
>
> Quick example:
>
>     main.js:
>     require('autoload').autoloadRegisteredGlobals(__dirname, require, 
> function() {
>       memo('hello');
>     });
>
>     memo.js:
>     registerGlobal(function memo(str) {
>       console.log(str);
>     });
>
> It's a pretty rough library right now and I haven't thought through the 
> gory specifics yet but as a proof of concept it works well. Currently I'm 
> not caching anything so it needs to read each source file individually on 
> startup, but I haven't noticed significant lagginess in start time in my 
> project. If this becomes an issue I could cache the symbols 
> and intelligently rescan the files when the stat time changes.
>
> Curious to hear thoughts on it, or if anyone has any other solutions to 
> the problem.
>

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to