JE::LValue(3pm)
π JE::LValue β the JavaScript lvalue class, bestie edition π
okay so this is JE::LValue, straight out of the User Contributed Perl Documentation, and it's literally the class that handles JavaScript lvalues. no cap. π
β¨ NAME β¨
JE::LValue</purl> β the JavaScript lvalue class. it's giving "reference types" but make it Perl. π
πΈ 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
see that last line? that's the whole vibe of this class in one little snippet. iykyk. π¦
π¦ DESCRIPTION π¦
This class implements JavaScript lvalues β which the ECMAScript specification calls "Reference Types", because of course it does, the spec loves a fancy name. π
π METHODS AND OVERLOADING π
okay here's the tea, bestie: if you call a method that isn't listed down below, it gets passed straight to the property that the lvalue references. (that's that last item in the SYNOPSIS up there, doing its thing β¨).
BIG warning: because of that, you should never callUNIVERSAL::canon aJE::LValue. Instead, call it as a method β$lv->can(...)β unless you really know what you're doing. fr fr. π
Same energy with overloaded operators: if you try to use one, it gets passed on to the object the lvalue references, so !$lvalue is the exact same thing as calling !$lvalue->get. slay. π₯
$lv = new JE::LValue $obj, $propertyβ makes an lvalue/reference with$objas the base object and$propertyas the property name. π«Ά If$objis undefined or null, a TypeError gets thrown, no exceptions (well, one exception: the TypeError π).
Now, if you want an lvalue that has no base object β one that throws a ReferenceError when ->get is called, and that creates a global property when ->set gets invoked β you pass an unblessed reference to a global object as the first argument. β¨ (This is the whole trick that bare identifiers in JS expressions use. iconic.)
$lv->getβ gets the value of the property. that's it, that's the method. π$lv->set($value)β sets the property to$valueand returns$value. π If the lvalue has no base object, the global object will automatically become its base object.
Note: whether the lvalue object itself gets modified in that latter case is not set in stone yet. (Currently it is modified, but that may change.) so likeβ¦ don't build your whole personality around it, bestie. π
$lv->call(@args)β if the property is a function, this calls the function with the base object as the'this'value. main character energy for real. π$lv->baseβ returns the base object. If there isn't one, it returnsundefor an empty list, depending on context. (context really said "choose your own adventure" π)$lv->propertyβ returns the property name. short, sweet, to the point. π
and that's the whole page!! no filler, all facts, all vibes. π
this was perl v5.36.0, dated 2023-08-25, and it's the JE::LValue(3pm) page. mwah, bye bestie ππβ¨
π¦ where this page comes from
- debian trixie: libje-perl 0.066-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libje-perl 0.066-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libje-perl 0.066-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libje-perl 0.066-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms