Packages in Javascript - Modular Javascript with Packages JS
Modular Javascript with Packages JS.
Packages JS is a small Javascript library for Javascript 1.6+ that introduces
the concept of ‘packages’ into the language, thus enabling authors to write
more modular and maintainable code.
Creating a package example.greeting in file example/greeting.js:
Package("example.greeting", function() {
// Create a function hello...
function hello() {
return "Hello world!";
};
// ...then export it for use by other packages
Export(hello);
// You need to supply a name for anonymous functions...
Export("goodbye", function() {
return "Goodbye cruel world!";
});
});
Using it from example.greetingtest in file example/greetingtest.js:
Package("example.greetingtest", ["example.greeting"], function(hello, log) {
// log is an implicit (exported by Packages JS) helper function that
// returns the log console when available, or a void object otherwise.
// Inside the callback, function hello is available. It has been injected
// by Packages JS with the function exported from example.greeting.
log().info(hello());
// Alternatively, you can Import objects from the dependencies.
var goodbye = Import("goodbye");
log().info(goodbye());
});
Check out the blog dedicated to this project:
http://packagesinjavascript.wordpress.com