Mathias Bynens (2013-10-19T05:12:01.000Z)
domenic at domenicdenicola.com (2013-10-26T03:00:41.396Z)
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.