Open Ocean-OS opened 2 weeks ago
By definition, an accessor (or a getter/setter) are for a property on an object. A variable isn't a property on an object, it's a binding, and overloading the way operators work for a binding would be a massive proposal unlikely to gain consensus, and either way would need to be separate from this proposal.
If you want to return a getter and setter in a function, you have to wrap it in an object property. This can limit some abilities to implement more reactivity in ECMAScript. For example:
is much less convenient and ergonomic than:
Returning accessors would allow for much simpler state management and reactivity in ECMAScript without any extra libraries or build steps. Some examples of where this could be used include:
$state
rune, in which a value is passed, and when set, triggers a state change in the DOM. (Svelte is a compiled language, but this would simplify functionality)useState
hook, in which a value is passed, and returns a getter and setter.ref
function, which declares a reactive state and returns an object with avalue
getter and setter.get
function andset
function.