`String.prototype.symbolAt()` (improved `String.prototype.charAt()`)

Allen Wirfs-Brock allen at wirfs-brock.com
Fri Oct 18 10:03:58 PDT 2013

On Oct 18, 2013, at 9:05 AM, Anne van Kesteren wrote:

> On Fri, Oct 18, 2013 at 4:58 PM, Mathias Bynens <mathias at qiwi.be> wrote:
>> On 18 Oct 2013, at 10:48, Anne van Kesteren <annevk at annevk.nl> wrote:
>>> When you phrase it like that, I see another problem with
>>> codePointAt(). You can't just replace existing usage of charCodeAt()
>>> with codePointAt() as that would fail for input with paired
>>> surrogates. E.g. a simple loop over a string that prints code points
>>> would print both the code point and the trail surrogate code point for
>>> a surrogate pair.
>> I disagree. In those situations you should just iterate over the string using `for…of`.
> That seems to iterate over code units as far as I can tell.
>  for (var x of "💩")
>    print(x.charCodeAt(0))
> invokes print() twice in Gecko.

No that's not correct, the @@iterator method of String.prototype is supposed to returns an interator the iterates code points and returns single codepoint strings.

The spec. for this will be in the next draft that I release.


More information about the es-discuss mailing list