javascript: fold modules

Fold modules rather than extending them for every new function.