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

Andrea Giammarchi andrea.giammarchi at gmail.com
Sat Oct 19 00:20:18 PDT 2013

so it's a for/of with a break when it finds a code point? if that's the
only use case I'd like to have an example of how convenient it is. I am
just wondering, not saying is not useful (trying to understand
when/where/why I'd like to use .at())


On Fri, Oct 18, 2013 at 10:12 PM, Mathias Bynens <mathias at qiwi.be> wrote:

> On 18 Oct 2013, at 17:51, Joshua Bell <jsbell at google.com> wrote:
> > Given that you can only use the proposed String.prototype.at() properly
> for indexes > 0 if you know the index of a non-BMP character or lead
> surrogate by some other means, or if you will test the return value for a
> trailing surrogate, is it really an advantage over using codePointAt /
> fromCodePoint?
> >
> > The name "at" is so tempting I'm imagining naive scripts of the form for
> (i = 0; i < s.length; ++i) { r += s.at(i); } which will work fine until
> they get a non-BMP input at which point they're suddenly duplicating the
> trailing surrogates.
> >
> > Pushing people towards for-of iteration and even Allen's Array.from(
> '𝌆𝌆𝌆'))[1] seems safer; users who need more subtle things have have
> codePointAt / fromCodePoint available and hopefully the knowledge to use
> them.
> Just because new features can be used incorrectly doesn’t mean the feature
> isn’t useful. `for…of` on strings and `String.prototype.at` are two very
> different things for two very different use cases. It’s a matter of using
> the right tool for the job, IMHO.
> In your example (iterating over all code points in a string), `for…of`
> should be used.
> `String.prototype.codePointAt` or `String.prototype.at` come in handy in
> case you only need to get the first code point or symbol in a string, for
> example.
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20131019/7c7c5d10/attachment.html>

More information about the es-discuss mailing list