To follow up, I think, this could be written even better by using either a dispatch array (not sure if this can be done in javascript but i think so) or a non flat switch (avoiding to go through all the if to get to the last method). I can have a look on this when i will get back from holidays (next week). The current implementation creates a really huge source file with very long dispatch methods (working ok anyway).