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

Andrea Giammarchi andrea.giammarchi at gmail.com
Fri Oct 18 10:06:53 PDT 2013


+1 for the simplified `at(symbolIndex)`

I would expect '𝌆'.at(1) to fail same way 'a'.charAt(1) or
'a'.charCodeAt(1) would.

I would expect '𝌆'.at(symbolIndex) to behave as `length` does based on
unique symbol (unicode extra) so that everyone, except RAM and CPU, will
have life easier with strings.

Long story short: there's no symbol at 1, the symbol is at 0 because the
size of that unicode string is 1

That said, I am sure the discussion went through this already ^_^





On Fri, Oct 18, 2013 at 9:57 AM, Allen Wirfs-Brock <allen at wirfs-brock.com>wrote:

>
> On Oct 18, 2013, at 7:21 AM, Rick Waldron wrote:
>
>
>
>
> On Fri, Oct 18, 2013 at 8:46 AM, Mathias Bynens <mathias at qiwi.be> wrote:
>
>> ES6 fixes `String.fromCharCode` by introducing `String.fromCodePoint`.
>>
>> Similarly, `String.prototype.charCodeAt` is fixed by
>> `String.prototype.codePointAt`.
>>
>> Should there be a method that is like `String.prototype.charAt` except it
>> deals with astral Unicode symbols wherever possible?
>>
>>     >> '𝌆'.charAt(0) // U+1D306
>>     '\uD834' // the first surrogate half for U+1D306
>>
>>     >> '𝌆'.symbolAt(0) // U+1D306
>>     '𝌆' // U+1D306
>>
>
> I think the idea is good, but the name may be confusing with regard to
> Symbols (maybe not?)
>
>
> Given that we have charAt, charCodeAt and codePointAt,  I think the most
> appropiate name for such a method would be 'at':
>      '𝌆'.at(0)
>
> The issue when this sort of method has been discussed in the past has been
> what to do when you index at a trailing surrogate possition:
>
>     '𝌆'.at(1)
>
> do you still get '𝌆' or do you get the equivalent of
> String.fromCharCode('𝌆'[1]) ?
>
> Allen
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20131018/28341207/attachment-0001.html>


More information about the es-discuss mailing list