Intercepting sets on array-like objects

Allen Wirfs-Brock allen at wirfs-brock.com
Thu Jun 8 22:59:11 UTC 2017


> On Jun 8, 2017, at 11:32 AM, Tab Atkins Jr. <jackalmage at gmail.com> wrote:
> 
> Naively, this requires a Proxy, so we can intercept uses of the []
> syntax.  However, we don't need all the rest of the Proxy
> functionality, just this one intercept - a setter function, just for
> `obj[foo]` rather than `obj.foo`.  Further, Typed Arrays already have
> *precisely* the functionality I'd like to use - they intercept setting
> using [], and convert it into the appropriate type of number.  AWB
> also proposed adding exactly this hook in the past (I think it was
> called "Array reformation" or something?).

that proposal page can be access here: https://web.archive.org/web/20160425220917/http://wiki.ecmascript.org/doku.php?id=strawman:object_model_reformation <https://web.archive.org/web/20160425220917/http://wiki.ecmascript.org/doku.php?id=strawman:object_model_reformation> 

the basic idea was that distinct internal methods (Proxy traps) are used for . and [] property accesses and that the default behavior for [ ] accesses is to look for specific symbol-keyed methods and if found defer the access logic to the method.  If not found the behavior is the same as for . accesses.

Allen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170608/954d7613/attachment-0001.html>


More information about the es-discuss mailing list