Yes, it's probably an oversight really. In the browser you've got window, and we should really have something similar. The 'root' is of type Hardware, so really we should have a hardware variable that can be accessed.
However, you can create a global variable just like:
function foo() {
global = "Hello";
var local = "World";
}
It works even for objects too - so you've actually got to be careful about using var in functions of you end up creating a lot of global stuff :)
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Yes, it's probably an oversight really. In the browser you've got
window
, and we should really have something similar. The 'root' is of typeHardware
, so really we should have ahardware
variable that can be accessed.However, you can create a global variable just like:
It works even for objects too - so you've actually got to be careful about using
var
in functions of you end up creating a lot of global stuff :)