`String.prototype.symbolAt()` (improved `String.prototype.charAt()`)
mathias at qiwi.be
Sat Oct 19 10:33:09 PDT 2013
On 19 Oct 2013, at 12:15, Bjoern Hoehrmann <derhoermi at gmx.net> wrote:
> 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 […]
Are you saying that changing the name to something that is longer than `at` would solve this problem?
> […] 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.
People are using `String.prototype.charAt()` incorrectly too, expecting it to return whole symbols instead of surrogate halves wherever possible. How would _not_ introducing a method that avoids this problem help?
More information about the es-discuss