ECMAScript仕様輪読会 #79
前回: ECMAScript仕様輪読会 #78
Cosenseの招待リンク: https://scrapbox.io/projects/esspec/invitations/85b96c9fa718ce5185e307196ed8fb53
connpass: https://esspec.connpass.com/
Discord: https://discord.gg/59S3y6weQj
ES Spec Draft: https://tc39.es/ecma262/
multipage: https://tc39.es/ecma262/multipage/
資料: https://speakerdeck.com/syumai/ecmascriptshi-yang-wodu-munonibi-yao-nazhi-shi-daiziesutoban
読み物リスト
Twitter 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
時事ネタ
https://github.com/tc39/ecma262/releases/tag/es2025-candidate-2025-03-31
自己紹介 (近況報告)
syumai syumai.icon
Twitter: https://twitter.com/__syumai GitHub: https://github.com/syumai
Go / TSを書いて暮らしてます
MCPを触ってます
https://github.com/syumai
https://ai-developer-meetup.connpass.com/event/353962/
iwatsurut
とくに、イベントもなく過ごしています。
仕事で、Go で Web システムを作ることになった。想定よりも複雑で、ちょとこまった。
igrep(山本悠滋)
https://github.com/igrep/
荷解がまだ完全には終わっておらず、ドライヤーや爪切りなど見つからないものが...
avante.nvimがやっと動いたが、やはりまだこなれない感じ
前回のあらすじ
https://claude.ai/share/8953315d-d452-4d05-8434-2fa83743d32d
今回の範囲
Object.getOwnPropertyDescriptor
code:js
Object.getOwnPropertyDescriptor(Array.prototype, Symbol.iterator);
/*
{
value: Function: values,
writable: true,
enumerable: false,
configurable: true
}
*/
Object.getOwnPropertyDescriptors
Array.prototypeから見つかったSymbol.unscopables
https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-symbol.unscopables
なぜか configurable: true だった
Object.
code:js
console.log(Object.getOwnPropertyNames(Array.prototype));
console.log(Object.getOwnPropertySymbols(Array.prototype));
/*
[
'length', 'constructor', 'at',
'concat', 'copyWithin', 'fill',
'find', 'findIndex', 'findLast',
'findLastIndex', 'lastIndexOf', 'pop',
'push', 'reverse', 'shift',
'unshift', 'slice', 'sort',
'splice', 'includes', 'indexOf',
'join', 'keys', 'entries',
'values', 'forEach', 'filter',
'flat', 'flatMap', 'map',
'every', 'some', 'reduce',
'reduceRight', 'toLocaleString', 'toString',
'toReversed', 'toSorted', 'toSpliced',
'with'
]
Symbol(Symbol.iterator), Symbol(Symbol.unscopables)
*/
Object.getPrototypeOf
code:js
console.log(Object.getPrototypeOf([]));
console.log(Object.getPrototypeOf({}));
class C1 {};
console.log(Object.getPrototypeOf(new C1()));
console.log(Object.getPrototypeOf(C1));
class C2 extends C1 {};
console.log(Object.getPrototypeOf(new C2()));
console.log(Object.getPrototypeOf(C2));
/*
Object(0) []
Object: null prototype {}
{}
{}
C1 {}
class C1
*/
【令和最新版】関数ベースのclass継承
code:js
function F1() {}
F1.prototype.m = function () {
console.log("called m!");
};
new F1().m();
function F2() {}
Object.setPrototypeOf(F2.prototype, F1.prototype);
new F2().m();
called m!
called m!
Object.groupBy
code:js
// Object.groupBy(undefined, () => {});
// TypeError: Object.groupBy called on null or undefined
// Object.groupBy(null, () => {});
// TypeError: Object.groupBy called on null or undefined
// Object.groupBy([], 1);
// TypeError: 1 is not a function
// itemsはiteratorならOK!なので、generatorとかでもいい
const obj = Object.groupBy("a", "b", "c", "d", "e", (item, k) => {
return k % 2; // 0 or 1 がkeyとして返る
});
/*
* {
* 0: a, c, e,
* 1: b, d
* }
*/
console.log(obj);
const obj2 = Object.groupBy("a", "b", "c", (item, k) => {
switch (item) {
case "a":
return 1;
case "b":
return "1";
case "c":
return 1.0;
}
});
console.log(obj2);
const m = Map.groupBy("a", "b", "c", "d", "e", (item, k) => {
return k % 2 === 0 ? +0 : -0; // 0 or 1 がkeyとして返る
});
console.log(m);
/*
Object: null prototype { '0': 'a', 'c', 'e' , '1': 'b', 'd' }
Object: null prototype { '1': 'a', 'b', 'c' }
Map(1) { 0 => 'a', 'b', 'c', 'd', 'e' }
*/