JE::LValue(3pm)

πŸ“¦
version 0.066 Β· 3 versions
, in debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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 call UNIVERSAL::can on a JE::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 $obj as the base object and $property as the property name. 🫢 If $obj is 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 $value and 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 returns undef or 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