Skip to content

Commit 50c13a9

Browse files
committed
Add explanation for the { position, codePoint } design
Closes #1
1 parent f8ec08b commit 50c13a9

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,18 @@ function* tokenise(input) {
103103
}
104104
```
105105

106+
## FAQ
107+
108+
1. Why does iterator emit an object instead of an array like other key-value iterators?
109+
110+
`[key, value]` format is usually used for entries of collections which can be directly indexed by `key`.
111+
112+
Unlike those collections, strings in ECMAScript are indexed [as 16-bit units of UTF-16 text](https://tc39.github.io/ecma262/#sec-terms-and-definitions-string-value) and not code points, so emitted objects won't have consequent indices but rather positions which might be 1 or 2 16-bit units away from each other.
113+
114+
To make the fact that they represent different measurement units and string representations explicit, we decided on `{ position, codePoint }` object format.
115+
116+
See [#1](https://github.com/tc39/proposal-string-prototype-codepoints/issues/1) for more details.
117+
106118
## Specification
107119

108120
You can view the rendered spec [here](https://tc39.github.io/proposal-string-prototype-codepoints/).

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1792,7 +1792,7 @@
17921792
text-align: right;
17931793
padding-right: 5px;
17941794
}
1795-
</style></head><body><div id="menu-toggle">☰</div><div id="menu-spacer"></div><div id="menu"><div id="menu-search"><input type="text" id="menu-search-box" placeholder="Search..."><div id="menu-search-results" class="inactive"></div></div><div id="menu-pins"><div class="menu-pane-header">Pins</div><ul id="menu-pins-list"></ul></div><div class="menu-pane-header">Table of Contents</div><div id="menu-toc"><ol class="toc"><li><span class="item-toggle">◢</span><a href="#sec-properties-of-the-string-prototype-object" title="Properties of the String Prototype Object"><span class="secnum">1</span> Properties of the String Prototype Object</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-string.prototype-@@iterator" title="String.prototype [ @@iterator ] ( )"><span class="secnum">1.1</span> String.prototype [ @@iterator ] ( )</a></li><li><span class="item-toggle-none"></span><a href="#sec-string.prototype-codepoints" title="String.prototype.codePoints ( )"><span class="secnum">1.2</span> String.prototype.codePoints ( )</a></li></ol></li><li><span class="item-toggle">◢</span><a href="#sec-string-iterator-objects" title="String Iterator Objects"><span class="secnum">2</span> String Iterator Objects</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-createstringiterator" title="CreateStringIterator ( string, kind )"><span class="secnum">2.1</span> CreateStringIterator ( <var>string</var>, <ins><var>kind</var></ins> )</a></li><li><span class="item-toggle">◢</span><a href="#sec-%stringiteratorprototype%-object" title="The %StringIteratorPrototype% Object"><span class="secnum">2.2</span> The %StringIteratorPrototype% Object</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-%stringiteratorprototype%.next" title="%StringIteratorPrototype%.next ( )"><span class="secnum">2.2.1</span> %StringIteratorPrototype%.next ( )</a></li></ol></li><li><span class="item-toggle-none"></span><a href="#sec-properties-of-string-iterator-instances" title="Properties of String Iterator Instances"><span class="secnum">2.3</span> Properties of String Iterator Instances</a></li></ol></li><li><span class="item-toggle-none"></span><a href="#sec-copyright-and-software-license" title="Copyright &amp; Software License"><span class="secnum">A</span> Copyright &amp; Software License</a></li></ol></div></div><div id="spec-container"><h1 class="version first">Stage 1 Draft / May 8, 2018</h1><h1 class="title">String.prototype.codePoints</h1>
1795+
</style></head><body><div id="menu-toggle">☰</div><div id="menu-spacer"></div><div id="menu"><div id="menu-search"><input type="text" id="menu-search-box" placeholder="Search..."><div id="menu-search-results" class="inactive"></div></div><div id="menu-pins"><div class="menu-pane-header">Pins</div><ul id="menu-pins-list"></ul></div><div class="menu-pane-header">Table of Contents</div><div id="menu-toc"><ol class="toc"><li><span class="item-toggle">◢</span><a href="#sec-properties-of-the-string-prototype-object" title="Properties of the String Prototype Object"><span class="secnum">1</span> Properties of the String Prototype Object</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-string.prototype-@@iterator" title="String.prototype [ @@iterator ] ( )"><span class="secnum">1.1</span> String.prototype [ @@iterator ] ( )</a></li><li><span class="item-toggle-none"></span><a href="#sec-string.prototype-codepoints" title="String.prototype.codePoints ( )"><span class="secnum">1.2</span> String.prototype.codePoints ( )</a></li></ol></li><li><span class="item-toggle">◢</span><a href="#sec-string-iterator-objects" title="String Iterator Objects"><span class="secnum">2</span> String Iterator Objects</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-createstringiterator" title="CreateStringIterator ( string, kind )"><span class="secnum">2.1</span> CreateStringIterator ( <var>string</var>, <ins><var>kind</var></ins> )</a></li><li><span class="item-toggle">◢</span><a href="#sec-%stringiteratorprototype%-object" title="The %StringIteratorPrototype% Object"><span class="secnum">2.2</span> The %StringIteratorPrototype% Object</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-%stringiteratorprototype%.next" title="%StringIteratorPrototype%.next ( )"><span class="secnum">2.2.1</span> %StringIteratorPrototype%.next ( )</a></li></ol></li><li><span class="item-toggle-none"></span><a href="#sec-properties-of-string-iterator-instances" title="Properties of String Iterator Instances"><span class="secnum">2.3</span> Properties of String Iterator Instances</a></li></ol></li><li><span class="item-toggle-none"></span><a href="#sec-copyright-and-software-license" title="Copyright &amp; Software License"><span class="secnum">A</span> Copyright &amp; Software License</a></li></ol></div></div><div id="spec-container"><h1 class="version first">Stage 1 Draft / May 19, 2018</h1><h1 class="title">String.prototype.codePoints</h1>
17961796
17971797
<!-- es6num="21.1.3" -->
17981798
<emu-clause id="sec-properties-of-the-string-prototype-object">

0 commit comments

Comments
 (0)