JavaScript: Reference a functions local scope as an object

No, there’s no way to reference the variable object of the execution context of a function binding object of the variable environment of the execution context (that’s what that thing is called [now; hence the strikethrough]; details in §10.3 of the specification). You can only access the limited view to it you get with arguments (which is very limited indeed).

Usually when I’ve wanted to do this, I’ve just put everything I wanted on an object and then used that (e.g., passed it into a function). Of course, any functions created within the context have access to everything in scope where they’re created, as they “close over” the context; more: Closures are not complicated.

Leave a Comment