On `String.prototype.codePointAt` and `String.fromCodePoint`

Erik Arvidsson erik.arvidsson at gmail.com
Tue Sep 24 21:59:15 PDT 2013


My concern is similar to Anne's. codePointAt will most likely not give
the right behavior and I'm concerned adding this without working
raising the bar significantly.

Since this is already implementable in ES3 I don't see why we should rush this?

I think we should apply the post ES6 process to this. Let's ship it
when we feel confident that we got this right.

On Tue, Sep 24, 2013 at 9:54 PM, Mathias Bynens <mathias at qiwi.be> wrote:
>> I think I'm convinced that String.fromCodePoint()'s design is correct,
>> especially since the rendering subsystem deals with code points too.
>
> Glad to hear.
>
>> String.prototype.codePointAt() however still feels wrong since you
>> always need to iterate from the start to get the correct code *unit*
>> offset anyway so why would you use it rather than the code *point*
>> iterator that is planned for inclusion?
>
> I think there are valid use cases for both.
>
> For example, `String.prototype.codePointAt()` makes it easy to get only the code point at the first position, i.e. `str.codePointAt(0)`. `for…of` iterates over all code points in the string by default.
>
> One key difference is that `String.prototype.codePointAt` is polyfillable in ES3/ES5, while `for…of` isn’t. This makes it easier to switch to `String.prototype.codePointAt` in existing code that is (incorrectly) using `String.prototype.charCodeAt` to loop over all code points in a string.
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss



-- 
erik


More information about the es-discuss mailing list