JS version - WIP

This is sort of working. It's hopefully close.

Care to take a look?