`of` operator ES7 proposal from Ian Bicking

Brendan Eich brendan at mozilla.org
Mon Mar 30 20:52:07 UTC 2015

Frankie Bagnardi wrote:
>     First, you shouldn’t assume this would be based on the
>     Symbol.iterator protocol.
> Would |Object.create(null, {[Symbol.iterator]: value: ...})| work as 
> it does in for..of?

No, as with instanceof and @@hasInstance in general, you wouldn't get 
membership test for free.

But unlike instanceof, you wouldn't get common case behavior for free 
either, so that's the downside. You'd have to provide a value such as 
Array#includes for the property named by Symbol.hasElement (or whatever 
the best name analogous to @@hasInstance is).

> It seems like the main problem would be infinite sequences. That means 
> either infinite loops (ugh), or the language/user setting an arbitrary 
> number of max values to check (ew).


> If I do have an arbitrary iterable, I need to easily create something 
> I can pass to for..of with |if (x of fn(xs))| where fn is provided by 
> ecmascript.

You'd need to implement a separate MOP hook, let's call it @@hasElement 
for now.


More information about the es-discuss mailing list