@brendaneich In JavaScript, the following creates an array of four items because the sailboat has a variation selector, forming (I think) a grapheme cluster. Can this behavior be made more intuitive?
[...

].length === 4 //true
-
-
Replying to @03d5d0a1
No, it can’t change as written. (Don’t break the web.) JS like Java and Win32 date from the mid-‘90s when 16 bits were considered enough for Unicode. Before the Astral Planes, and the sailboats...
1 reply 0 retweets 1 like -
Replying to @BrendanEich
Understood. But given the spread syntax was introduced in ~2015 I would have expected it to "gather the characters" together more intuitively. It looks like three boat characters, but "JavaScript" tells me there are four items. Water under bridge. Wondering about future APIs.
1 reply 0 retweets 0 likes -
Replying to @03d5d0a1
I wrote “as written” because we cannot change string iteration (DBTW). But we are already living in the future: https://github.com/tc39/proposal-intl-segmenter/blob/master/README.md …
1 reply 0 retweets 3 likes -
Replying to @BrendanEich
(Spread can’t select nonstandard iterator, but you can. Tagging
@mathias@littledan to rewrite your example as I am on phone!)1 reply 0 retweets 2 likes -
Oh OK. Thanks for the explanation.
1 reply 0 retweets 0 likes -
Replying to @03d5d0a1 @BrendanEich and
But didn't the spread operator introduce a new method of iterating strings that was more "unicode compliant" (Unicode codepoints, not graphemes I suppose)? If so DBTW seems moot, given it was new behavior in 2015?
1 reply 0 retweets 0 likes -
ES2015 introduced `String.prototype[Symbol.iterator]` which iterates over Unicode code points (as opposed to UCS-2/UTF-16 code units, which is how JS indexes strings). Spreading a string just uses that iterator.
2 replies 0 retweets 1 like
You’re right that we could’ve chosen something else than “iterate over code points” back then — but iterating over grapheme clusters (cfr. Intl.Segmenter) is locale-dependent, and thus not a great fit for a general-purpose mechanism in the language.
-
-
Replying to @mathias @littledan
What is the status of Intl.Segmenter? I don't see it in Node 10.16.3, for example. Thanks.
2 replies 0 retweets 1 like -
- 8 more replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
JavaScript, HTML, CSS, HTTP, performance, security, Bash, Unicode, i18n, macOS.