This is not gona work... :(... Espruino is a server like context... window and document (global variables) are undefined, as are all the other view oriented browser global variables... With Espurino it's more like a node.js or Rhino environment... If you want your code to work unchanged, you have to come up with the emulation of these things. --- And like your idea to have it run anywhere... (I did the same for some stuff: developed in the browser emulating Espruino context, and then move it over...).
There is no html / view DOM, and therefore all these functions are not there. I did not look in detail into all of your code, but I think it is feasible.
I'll sit down and will give you some pointers... until then, have fun with Espruino.
© Espruino, powered by microcosm.
Report a problem