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

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

> Le 9 mai 2019 à 23:17, Tom Barrasso <tom at> 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:

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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list