Toying with Javascript modules

I'm not a fan of rewriting things from scratch, but I also dislike bloating small things with lots of frameworks when they are not needed.

Reading today about structuring javascript code in modules and how to communicate them I decided to make a small example to see how clean and small would be a very basic pub-sub system communicating those modules (and avoid callback-hells at least for normal scenarios). Nothing fancy, nothing big, just the skeleton and most basic functionality, specially since I will probably just use it for small pet projects and experiments, where a framework is overkill.

The code has no comments (but doesn't need them I think), I'm not using anything nice to do on-demand module loading, and basically there is no demo apart from a single html file doing some sample config, instantiations and message sending.

Checking that modules being registered implement required methods (have certain functions, as there are no interfaces in JS) and a bit more of error handling would be nice too, I might add it when I start using the code in a real scenario and not this quick afternoon tests.

So, taking into account it is nothing impressive, I like that it is pretty small, full sources counting 3 modules below 200 lines of code in total. Javascript looks ugly and messy at first, but can be "tamed" and then looks nicer.

You can check all the code at GitHub if you wish.

Comments?

Posted by Kartones on 2013-08-18