Yes, I know what `String#at` is supposed to do.

I was pointing out that `String#at` makes it easy to do the wrong
thing.  If you do `Array.from(str)` then you suddenly have a complete
random-access data structure where you can find out the number of code
points in the String, iterate it in reverse from the end to the start,
slice it, find the midpoint, etc.  `Array.from` looks like an O(n)
operation, and it is -- so it encourages developers to cache the value
and reuse it.

That said, I can see where a lexer might want to use `String#at`,
being careful to do the correct index bump based on `result.length`.
However, the fastest JS lexers don't create String objects, they
operate directly on the code point (see
http://marijnhaverbeke.nl/acorn/#section-58).  So I'm -0, mostly
because the name isn't great.  But I have exactly zero say in the
matter anyway.  So I'll shut up now.
 --scott
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to