NAME¶
JE::LValue - JavaScript lvalue class
SYNOPSIS¶
use JE::LValue;
$lv = new JE::LValue $some_obj, 'property_name';
$lv->get; # get property
$lv->set($value) # set property
$lv->some_other_method # same as $lv->get->some_other_method
DESCRIPTION¶
This class implements JavaScript lvalues (called "Reference Types" by
the ECMAScript specification).
METHODS AND OVERLOADING¶
If a method is called that is not listed here, it will be passed to the property
referenced by the lvalue. (See the last item in the SYNOPSIS, above.) For this
reason, you should never call "UNIVERSAL::can" on a JE::LValue, but,
rather, call it as a method ("$lv->can(...)"), unless you really
know what you are doing.
Similarly, if you try to use an overloaded operator, it will be passed on to the
object that the lvalue references, such that "!$lvalue" is the same
as calling "!$lvalue->get".
- $lv = new JE::LValue $obj, $property
- Creates an lvalue/reference with $obj as the base object and $property as
the property name. If $obj is undefined or null, a TypeError is thrown. To
create a lvalue that has no base object, and which will throw a
ReferenceError when "->get" is called and create a global
property upon invocation of "->set", pass an unblessed
reference to a global object as the first argument. (This is used by bare
identifiers in JS expressions.)
- $lv->get
- Gets the value of the property.
- $lv->set($value)
- Sets the property to $value and returns $value. If the lvalue has no base
object, the global object will become its base object automatically.
<Note:> Whether the lvalue object itself is modified in the latter
case is not set in stone yet. (Currently it is modified, but that may
change.)
- $lv->call(@args)
- If the property is a function, this calls the function with the base
object as the 'this' value.
- $lv->base
- Returns the base object. If there isn't any, it returns undef or an empty
list, depending on context.
- $lv->property
- Returns the property name.