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

Bjoern Hoehrmann derhoermi at gmx.net
Sat Oct 19 10:15:05 PDT 2013

* Allen Wirfs-Brock wrote:
>The utility of a hypothetical 'at' method is presumably exactly that of 'codePointAt'. 
>   str.at(p)
>would just be a convenience  for expressing
>   String.fromCodePoint(str.codePointAt(p))
>So the real question is probably, how common is that  use case.

Certainly not common enough to warrant a two-character method on the
native string type. Odds are people will use it incorrectly in an
attempt to make their code look concise, not understanding that it'll
retrieve a substring of .length 1 or 2, possibly consisting of a lone
surrogate, based on a 16 bit index that might fall in the middle of a
character; the problematic cases are fairly rare, so it's hard to
notice improper use of `.at` in automated testing or in code review.
Björn Höhrmann · mailto:bjoern at hoehrmann.de · http://bjoern.hoehrmann.de
Am Badedeich 7 · Telefon: +49(0)160/4415681 · http://www.bjoernsworld.de
25899 Dagebüll · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/ 

More information about the es-discuss mailing list