You can just do `if (Symbol.iterator in potentialIterable)`.
________________________________
From: Caitlin Potter<mailto:[email protected]>
Sent: ‎3/‎1/‎2014 22:01
To: [email protected]<mailto:[email protected]>
Subject: Re: Re: Final iterator spec

I have a concern with these, which isn't 100% related to this thread, but is on 
the topic of iterators.

So, in Dart, we have this nice option of basically saying `if (OBJ is 
Iterable)`, and we'll be able to know easily if an object conforms to that 
particular interface.

Admittedly, this construct makes a lot more sense in Dart than it does in 
Javascript, but it would be nice to have some kind of helper which will 
determine if
an object adheres to the Iterable interface. For instance, `Object.isIterable() 
=> true` if the interface is present in the object's prototype.

It would be nice to have a convenience function for this largely because it 
feels like the VM should have an easier time knowing if an object is iterable 
or not, and may be able to cache its knowledge of the Iterable status of an 
object, for performance reasons.

Maybe it would be good if a helper function like this would also determine that 
the return value of `@@iterator()` also conforms to the Iterator interface, or 
maybe that's not super important. But in any case, I could see utilities like 
this being very helpful.

Maybe that ship has sailed, but if something like that would hurt the harmony 
status of iterators, I would be interested in hearing the specific reasons 
against it.

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to