I did it like this because I wanted to create the drawing loop as efficient as possible, without switches or conditionals. That method gets executed per pixel so the less logic the better.
I instrumented the code and using conditionals resulted in 2x the generation time per loop. These loops are executed only once so the VM doesn't have a chance to optimise them.
Stating the obvious, but I'm pretty sure that there are no longer any purely interpreting JS engines around, it's all JIT or AOT compiled, so optimizing for a compilation scenario definitely makes sense.
If someone knows a better way I'm all ears!