Re: How to correctly spec sequences requiring an iterable

On Nov 15, 2013, at 10:07 AM, Boris Zbarsky wrote:

> On 11/15/13 12:55 PM, Allen Wirfs-Brock wrote:
>> Now, that's an interesting question.
>> 
>>     "thisIsAPrimitiveString"[Symbol.interator]
>> 
>> Returns the value of
>>      String.prototype[@@iterator]
> 
> Sure; the question is whether I check whether I have an object first.

The Invoke abstract operator that GetIterator uses does a ToObject before doing the property lookup.  It then throws away that result and passes the original primitive value as the this value of the function call.

The ToObject test is such that it can be optimized away into an explicit Type test and a direct lookup using the implied prototype.

> 
> Note that I've seen people wanting to overload "DOMString or sequence<DOMString>" and current JS libraries commonly support that (via typeof tests).
> 

This is an API design issue and I'd argument that such an overload is bad design.

For example, if you want to create a single element array containing a string value the ES6 array APIs would have you say:
    Array.of("abc")  //same as: ["abc"]
rather than
    Array.from("abc")  //same as: ["a", "b", "c"]
is a
   

Received on Friday, 15 November 2013 18:37:35 UTC