-
• #2
Have you tried
trace(this)
? -
• #3
this is a runtime value and reference of the current context object... trace takes this to show what is going on for the passed object - and with that it is a relative root. If invoked in root context it will pass in the one I'm looking for, but it does not reveal it's variable name. I'm looking for the absolute root's variable name so I can use it to go after state and behavior (vars/functions) defined in the root context.
-
• #4
As of about 5 minutes ago it's called
global
, like in node.js.But before that, there wasn't one. The best equivalent was just to add
var global = this
at the top of your code.However, right now
global
isn't different for modules, so it will point to the same basic object even if you're in a module... Which I guess probably isn't that great. -
• #5
In node.js, each module has its own top-level scope, but they all have access to the
global
object. Although, the use of global variables is frowned upon (bad for testability and various other reasons) :)http://nodejs.org/api/globals.html#globals_global
I think the same would make sense for Espruino, each module having its own scope and the ability to access the global
global
object for shared state. -
• #6
Ok, that's great - that's what happens right now (only there's no
module
variable I'm afraid).I had seen that page and assumed that the value of
global
changed if you were in a module.
This question was asked quite a while ago - it was though triggered by specific challenge and resolved satisfactorily for that need, therefore I'm asking the question again.
What is the root context's variable name? (accessible from within any context?)
In Javascript in a browser, this would be the window object. In @Gordon's terminology it is called the root context.