Proposal: Symbol.inObject well-known symbol to customize the "in" operator's behavior

Isiah Meadows isiahmeadows at gmail.com
Sun May 12 07:53:36 UTC 2019


This example could be fixed by passing `{}` as the proxy target.

On Fri, May 10, 2019 at 01:23 Claude Pache <claude.pache at gmail.com> wrote:

>
>
> Le 9 mai 2019 à 23:17, Tom Barrasso <tom at barrasso.me> a écrit :
>
> If this Symbol were seriously considered I believe it would expand the
> meaning of the in operator as you’re correct, this is definitely not it’s
> current intention.
>
>
> The `in` operator has a well-defined meaning, that *by design* you can’t
> ignore even with the fanciest proxy. (And no, there is no hope for
> introducing a new mechanism that allows to overcome those limitations,
> since they are by design.)
> Consider for example the following proxy around a String object:
>
> ```js
> function conflateInAndIncludes(str) {
>     return new Proxy(Object(str), {
>         has(target, key) { return str.includes(key) }
>     })
> }
>
> var FrankensteinFood = conflateInAndIncludes("food");
>
> "foo" in FrankensteinFood // true, yeah!
> "bar" in FrankensteinFood // false, yeah!
> "length" in FrankensteinFood // TypeError: proxy can't report a
> non-configurable own property '"length"' as non-existent
> ```
>
>
> —Claude
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-- 
-----

Isiah Meadows
contact at isiahmeadows.com
www.isiahmeadows.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20190512/197a32f0/attachment.html>


More information about the es-discuss mailing list