Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You already have this with CommonJS packages and modules as used by Node, RingoJS, Akshell and others.

The latest additions to require() mean that if you do something like require('foo') and there's a directory 'foo' in your require path that contains a package.json file (i.e. if you have package foo installed via the likes of npm), then the main module mentioned in that package.json file (which contains the meta data Joe speaks of) is immediately available to you. The module isn't a function, but rather an object, but then JavaScript isn't a purely functional language.

Now, admittedly, currently you need to pre install the packages, but there's no reason why require couldn't be modified to install them for you if they're unavailable or, if your code ran on a platform like Akshell, the packages wouldn't already be available to you.



Actually in node at least modules can export functions directly, just assign a function to `module.exports` and when you require() that module you'll get a function back. Plus you can add attributes to that function since functions are also objects.


That's cool, I had overlooked that. I guess the point is that there's no key value store for modules, whereas for packages there's npm.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: