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())
Thanks On Fri, Oct 18, 2013 at 10:12 PM, Mathias Bynens <[email protected]> wrote: > On 18 Oct 2013, at 17:51, Joshua Bell <[email protected]> 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 > [email protected] > https://mail.mozilla.org/listinfo/es-discuss >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

