10.2.1 Environment Records

2010-05-06

There are two kinds of Environment Records:
- Declarative Environment Records
Associate an Identifier with a value. This is used when you declare a variable or function.
- Object Environment Records
This is used for declaring the properties of an object.

See also 10.2.

Environment Records (both types) have the following set of methods which are explained in detail in the next few paragraphs. Their algorithm is slightly different between the two types.

- Boolean HasBinding(N:String)
Return true if this record has a binding for N. False otherwise.
- Undefined CreateMutableBinding(N:String, D:Boolean)
Create binding with name N. If D is true, the binding may be deleted.
- Undefined SetMutableBinding(N:String, V:mixed, S:Boolean)
Set the value of a binding with name N to value V. S denotes strict mode, and throws an error if unable to set the value for some reason.
- mixed GetBindingValue(N:String, S:Boolean)
Get the value of a binding with name N. S denotes strict mode, and throws an error if non-existant or uninitialized binding.
- Undefined DeleteBinding(N:String)
Delete binding N from record. Returns true if the binding was deleted or did not exist at all. False otherwise.
- mixed ImplicitThisValue()
"Returns the value to use as the this value on calls to function objects that are obtained as binding values from this environment record". I think this is a scoping thing, have to check out further.

Environment Records also have a flag, provideThis:Boolean, which in my examples simple holds the this value if the record has one. Used by ImplicitThisValue() and can only be true for Object Environment Records (makes no sense in a scope).

The explanation given by the specification of the differences between the two types is a little shallow. The declarative records track which variables and functions have been declared in the current scope. The object record tracks which properties have been declared on the environment it belongs to, like in a with statement.