> ---------- Forwarded message ----------
> From: Sebastian Malton <[email protected]>
> To: Pranay Prakash <[email protected]>, "Michał Wadas" <
> [email protected]>
> Cc: Matthew Tedder <[email protected]>, es-discuss <
> [email protected]>
> Bcc:
> Date: Fri, 11 May 2018 18:25:08 -0400
> Subject: Re: Suggested Enhancement to ecmascript
> What would be nice is if we could have a good way of watching a variable.
> Maybe a built in way to create a custom event emitter.
>

Watching a variable directly might not be available.  That said, if you're
willing to wrap the variable in an object, it's very doable via property
descriptors.  They allow you to implement getters and setters which refer
to another property, either publicly exposed or in a closure.

Keep in mind private variables don't really exist - yet - in ECMAScript.
They can be achieved right now through a JavaScript Proxy, but that's
pretty heavy-weight, and tricky to get right.  I've been working on a
proxy-based library to do exactly that, named es-membrane... and I'm still
looking for help for the times when I'm just too busy.

-- 
"The first step in confirming there is a bug in someone else's work is
confirming there are no bugs in your own."
-- Alexander J. Vincent, June 30, 2001
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to