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

Claude Pache claude.pache at gmail.com
Fri May 10 05:23:26 UTC 2019



> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20190510/6aa31b2c/attachment.html>


More information about the es-discuss mailing list