W3C home > Mailing lists > Public > public-script-coord@w3.org > October to December 2013

Re: How to correctly spec sequences requiring an iterable

From: Allen Wirfs-Brock <allen@wirfs-brock.com>
Date: Fri, 15 Nov 2013 10:37:02 -0800
Cc: Jason Orendorff <jason.orendorff@gmail.com>, public-script-coord@w3.org
Message-Id: <EA7C03E3-EE04-48AA-869F-16169F3E2319@wirfs-brock.com>
To: Boris Zbarsky <bzbarsky@mit.edu>

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

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:14:19 UTC