NAME

JE::Scope - JavaScript scope chain (what makes closures work)

DESCRIPTION

JavaScript functions run within the scope in which they are defined. Each function has a call object (aka activation object) that contains any vars defined in the function. When a variable is accessed, the one in the call object will be used, if any. Otherwise the one in the containing function will be used, if the function is nested, and so on until the search reaches the global scope.

Objects of this class consist of a reference to an array, the first element of which is the global object. Subsequent elements are call objects. (Think of it as a stack.)

A call object is quite a simple creature, so I've not seen any need to make a special Perl class for it. I've just used a hashref.

THE METHOD

The only method provided by this package is var, which searches through the call chain, starting at the end of the array, until it finds the variable named by the first argument. If a second argument is provided, it is assigned to the variable. If the variable cannot be found, it is created if an assignment is being made. An exception is thrown otherwise.

To do: This class needs another method, new_var, for creating a new variable on the nearest end of the scope chain (the top of the scope stack)

To do: And an lvalue method, which will return a JE::LValue object, to be used by JE::Code.

CONSTRUCTOR

None. Just bless an array reference. You should not need to do this because it is done for you by the JE::Object::Function class.

SEE ALSO

1 POD Error

The following errors were encountered while parsing the POD:

Around line 69:

=over without closing =back