ECMAScript仕様輪読会 #104
前回: ECMAScript仕様輪読会 #103
Cosenseの招待リンク: https://scrapbox.io/projects/esspec/invitations/85b96c9fa718ce5185e307196ed8fb53
connpass: https://esspec.connpass.com/
ES Spec Draft: https://tc39.es/ecma262/
multipage: https://tc39.es/ecma262/multipage/
X hashtag: #esspec
便利ツール
esspec-memo: https://tars0x9752.github.io/esspec-memo/esspec.html
Scrapbox Codeblock Generator: https://vzvu3k6k.github.io/scrapbox-codeblock/
TC39 Terminology: https://github.com/tc39/how-we-work/blob/main/terminology.md
esmeta playground: https://es-meta.github.io/playground/
時事ネタ
ES2026リリース!
https://github.com/tc39/ecma262/releases/tag/es2026
JSConf
https://jsconf.jp/2026/ja
TSKaigi Sendai 2026
https://sendai.tskaigi.org/
自己紹介 (近況報告)
syumai syumai.icon
X: https://x.com/__syumai GitHub: https://github.com/syumai
TSを書いて暮らしてます
インターネット回線が速くなりました
フレッツ光クロス
iwatsurut
とくに、イベントもなく過ごしています。
igrep(山本悠滋)
https://github.com/igrep/
関数型まつり 2026 は今週末!資料はまだ出来てない!
6/20 にPC故障からのゲーミングノートPC購入。設定祭りでまた寝不足気味
Zoomの声紋登録も改めてやり直したがどうだ?
maru。(まる)
https://x.com/sbleru
https://github.com/sbleru
主にTSで仕事してます。React, Node。
fable使ってずっとやりたかったけどやれてなかった重めのタスクの実装プラン作らせていた(実装と検証とプランニングいったんさせてfable無くなっても大丈夫なように。)
長崎の廃墟行ってました。池島。
https://saruku.nagasaki-visit.or.jp/ikeshima/
yebis0942
https://github.com/yebis0942
Go, TypeScriptで仕事をしてます。
今からFableロスを感じています。
画像処理とかでOpus 4.8が匙を投げた問題を解決してくれた
人間は「賢い…」と言いながらコミットする作業をしていた
同時編集JavaScript Playground
前半
https://jssync.syumai.workers.dev/rooms/esspec_a
後半
https://jssync.syumai.workers.dev/rooms/esspec_b
前回のあらすじ
https://syumai.github.io/esspec/summaries/summary-103.html
今回のメモ
RegExpのlastIndex
code:js
// ===== Code =====
const str = "foofoofoobarfoo";
const regex = /foo/y;
console.log(regex.test(str)); // true
console.log(regex.lastIndex); // 3
console.log(regex.test(str)); // true
console.log(regex.lastIndex); // 6
console.log(regex.test(str)); // true
console.log(regex.lastIndex); // 9
console.log(regex.test(str)); // false
console.log(regex.lastIndex); // 0
console.log(regex.test(str)); // true
console.log(regex.lastIndex); // 3
// ===== Output =====
true
3
true
6
true
9
false
0
true
3
code:js
// ===== Code =====
const str = "foofoofoobarfoo";
const regex = /foo/y;
console.log(str.search(regex)); // 0
console.log(regex.lastIndex); // 0
console.log(str.search(regex)); // 0
console.log(regex.lastIndex); // 0
// ===== Output =====
0
0
0
0
code:js
// ===== Code =====
const str = "ABCDEABCDE";
console.log(str.replaceAll("BC", "bc"));
console.log(str.replaceAll("", "!"));
console.log(str.replaceAll(new RegExp("", "g"), "!"));
// ===== Output =====
AbcDEAbcDE
!A!B!C!D!E!A!B!C!D!E!
!A!B!C!D!E!A!B!C!D!E!
code:js
// ===== Code =====
{
const str = "ABCDEABCDE";
console.log(
str.replaceAll("CD", function (searchString, matchPosition, string) {
return string
.substring(matchPosition, matchPosition + searchString.length)
.toLowerCase();
}),
);
}
// ===== Output =====
ABcdEABcdE
code:js
// ===== Code =====
// https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/replace#%E7%BD%AE%E6%8F%9B%E6%96%87%E5%AD%97%E5%88%97%E3%81%A8%E3%81%97%E3%81%A6%E3%81%AE%E9%96%A2%E6%95%B0%E3%81%AE%E6%8C%87%E5%AE%9A
{
const input = '<div id="aaa"><span class="bbb"></span></div>';
const re = /<(\/?)(\w+)(?:\s+(\w+)="(^"*?)")?>/g;
console.log(
input.replaceAll(re, (search, isStart, element, attribute, value, position, string) => {
return JSON.stringify({
isStart: isStart === "", element, attribute, value
}, null, 2) + "\n";
}),
);
}
// ===== Output =====
{
"isStart": true,
"element": "div",
"attribute": "id",
"value": "aaa"
}
{
"isStart": true,
"element": "span",
"attribute": "class",
"value": "bbb"
}
{
"isStart": false,
"element": "span"
}
{
"isStart": false,
"element": "div"
}
code:js
// ===== Code =====
const str = "ABCDEABCDE";
console.log(str.replaceAll("BC", "$&"));
// ===== Output =====
ABCDEABCDE
code:js
// ===== Code =====
// https://tc39.es/ecma262/multipage/text-processing.html#sec-string.prototype.slice
{
const s = "ECMAScript";
console.log(s.slice(0));
console.log(s.slice(-Infinity));
console.log(s.slice(0, 4));
console.log(s.slice(4, 100));
console.log(s.slice(-6));
console.log(s.slice(-6, -5));
console.log(s.slice(-6, Infinity));
}
{
console.log(String.prototype.slice.call({}, 1, 7));
}
{
class Hoge {}
console.log(String.prototype.slice.call(new Date(), 1, 7));
console.log(String.prototype.slice.call(new Date(), 0, 3));
console.log(String.prototype.slice.call(new Hoge(), 0, 3));
}
// ===== Output =====
ECMAScript
ECMAScript
ECMA
Script
Script
S
Script
object
ue Jul
Tue
[ob
code:substring-vs-substr.js