In V8 at least, in the debugger, you see local
, script
and global
categorizing the variables.
I got a reference to global
. All you do for that is set this
on entry to a property to use later if need be.
However, I can't find how to save a reference to the script
object. I think it exists because that's what the debugger is looping through in the watch window.
Before ES6, All declarations outside a function (and function declaration themselves) were properties of global object. After ES6, There are two kinds of global records:
Object record- Same as ES5.
- Function declarations
- Function generators
- Variable assignments
var
Declarative record - New
let
,const
,class
, etc
Those in the declarative record are not accessible from the global "object", though they are globals themselves. They are accessible from the script, but the object/internal data structure holding the declarative records itself is not accessible or enumerable from inside the script. This declarative record is shown in v8 debugger as properties of script
object.