ECMAScript仕様輪読会 #80
前回: ECMAScript仕様輪読会 #79
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://note.com/fec_hokkaido/n/naf4cd828afab
もうすぐ締め切り
フロントエンドカンファレンス東京
JSConf
フロントエンドカンファレンス関西
tsgo preview
https://codezine.jp/article/detail/21588
自己紹介 (近況報告)
syumai syumai.icon
Twitter: https://twitter.com/__syumai GitHub: https://github.com/syumai
Go / TSを書いて暮らしてます
肘の骨にヒビが入りました
iwatsurut
とくに、イベントもなく過ごしています。
仕事で、Go で Web システムを作ることになった。想定よりも複雑で、ちょとこまった。
igrep(山本悠滋)
https://github.com/igrep/
Claude Codeを特にClaude Code用のプラグインも使わず自前のプラグイン https://gitlab.com/igrep/vim-terminal-registry を活用すればいけそう
https://docs.anthropic.com/en/docs/claude-code/ide-integrations にある機能で十分賄えそう?
前回のあらすじ
https://claude.ai/share/4033b33e-d740-4867-8dd1-5a2d7c806614
今回の範囲
Object.hasOwn
code:js
const o1 = {
a: 1,
};
console.log(Object.hasOwn(o1, "a"));
console.log(Object.hasOwn(o1, "b"));
console.log("a" in o1);
console.log("b" in o1);
const o2 = {
b: 2,
};
Object.setPrototypeOf(o2, o1);
console.log(Object.hasOwn(o2, "a"));
console.log(Object.hasOwn(o2, "b"));
console.log("a" in o2);
console.log("b" in o2);
/*
true
false
true
false
false // ここがinと違ってtrueにならない!
true
true
true
*/
Object.preventExtensions
code:js
const buffer1 = new ArrayBuffer(8);
const buffer2 = new ArrayBuffer(8, { maxByteLength: 16 });
console.log(buffer1.resizable);
// Expected output: true
console.log(buffer2.resizable);
// Expected output: false
console.log(Object.preventExtensions(new Uint8Array(buffer1)));
console.log(Object.preventExtensions(new Uint8Array(buffer2)));
/*
false
true
Uint8Array(8) 0, 0, 0, 0, 0, 0, 0, 0, buffer: ArrayBuffer(8), byteLength: 8, byteOffset: 0, length: 8, Symbol(Symbol.toStringTag): 'Uint8Array'
Uncaught TypeError: Cannot prevent extensions
at Object.preventExtensions (<anonymous>)
at <anonymous>:11:23
*/
Object.prototype
%Object.prototype% はExtensible
code:js
"use strict";
console.log(Object.keys(Object.prototype));
Object.prototype.a = 1;
Object.prototype.b = 2;
console.log(Object.keys(Object.prototype));
console.log({}.a, {}.b);
class A {}
console.log(new A().a, new A().b);
console.log(Object.create(null).a, Object.create(null).b);
/*
[]
'a', 'b'
1 2
1 2
undefined undefined
*/
Object.prototypeへのObject.setPrototypeOfはnullしか通らない
https://tc39.es/ecma262/#sec-set-immutable-prototype
code:js
console.log(Object.getPrototypeOf(Object.prototype));
const o = {
a: 1,
};
console.log(Object.setPrototypeOf(Object.prototype, o)); // NG
console.log(Object.setPrototypeOf(Object.prototype, null)); // OK
Object.prototype.constructor
実は値を差し替え可能
code:js
Object.prototype.constructor
Function: Object
Object.prototype.constructor = Function.prototype.constructor
Function: Function
Object.prototype.constructor
Function: Function
new Object()
{}
(new Object())()
Uncaught TypeError: (intermediate value) is not a function
Object.prototype.hasOwnProperty
code:js
({a:1}).hasOwnProperty("a");
true
({a:1}).hasOwnProperty("b");
false
({a:1}).hasOwnProperty("b");
false
Object.prototype.hasOwnProperty.bind(undefined)("a")
Uncaught TypeError: Cannot convert undefined or null to object
at hasOwnProperty (<anonymous>)
Object.prototype.hasOwnProperty.bind({})("a")
false
Object.prototype.hasOwnProperty.call({}, "a")
false
Object.prototype.hasOwnProperty.call({a:1}, "a")
true
Object.prototype.hasOwnProperty.call(null, "a")
Uncaught TypeError: Cannot convert undefined or null to object
at hasOwnProperty (<anonymous>)
Object.prototype.isPrototypeOf
code:js
const o1 = {};
undefined
const o2 = {};
undefined
const o3 = {};
undefined
Object.setPrototypeOf(o2, o1);
{}
Object.setPrototypeOf(o3, o2);
{}
o1.isPrototypeOf(o3);
true
Object.prototype.toLocaleString
code:js
({}).toLocaleString()
'object Object'
(10000).toLocaleString()
'10,000'
(10000).toString()
'10000'
Object.prototype
code:js
Object.prototype.toString.call(10000)
'object Number'
Object.prototype.toString.call(true)
'object Boolean'
Object.prototype.toString.call(undefined)
'object Undefined'
Object.prototype.toString.call(null)
'object Null'
Object.prototype.toString.call([])
'object Array'
Object.prototype.toString.call("")
'object String'
Object.prototype.toString.call(new Date())
'object Date'
Object.prototype.toString.call(() => {})
'object Function'
Object.prototype.toString.call(1n)
'object BigInt'
Object.prototype.toString.call(new Uint8Array())
'object Uint8Array'
class A {}
undefined
Object.prototype.toString.call(new A())
'object Object'
Object.prototype.toString.call(async () => {})
'object AsyncFunction'
(async () => {})Symbol.toStringTag
'AsyncFunction'
const o = { Symbol.toStringTag: "MyObj" };
undefined
o.toString()
'object MyObj'