Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
知られているようで知られていない JavaScriptの仕様 4選
Search
syumai
November 14, 2025
Programming
1.3k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
知られているようで知られていない JavaScriptの仕様 4選
syumai
November 14, 2025
More Decks by syumai
See All by syumai
作って学ぶ、 JSX (TSX) ランタイムの基本
syumai
7
1.8k
Oxlintのカスタムルールの現況
syumai
6
1.3k
Oxlintはいかにしてtsgolintのlint ruleを呼び出しているのか
syumai
2
1.4k
『[入門] Cloudflare Workers』本はなぜ誕生したのか
syumai
0
460
tsgolintはいかにしてtypescript-goの非公開APIを呼び出しているのか
syumai
9
3.2k
CloudflareのSandbox SDKを試してみた
syumai
0
940
実践AIチャットボットUI実装入門
syumai
9
4.3k
ProxyによるWindow間RPC機構の構築
syumai
3
1.5k
CloudflareのChat Agent Starter Kitで簡単!AIチャットボット構築
syumai
2
1.3k
Other Decks in Programming
See All in Programming
生成AI導入の「期待外れ」を乗り越える ー 開発フロー改革が目指す、真の組織変革
starfish719
0
2.2k
信頼性について考えてみる(SRE NEXT 2026 miniLT)
hayama17
0
210
【やさしく解説 設計編・中級 #4】ルールの寿命と、システムの年輪
panda728
PRO
2
170
【やさしく解説 設計編・中級 #6】良いアーキテクチャとは ~ 一本の登り道の、行き先 ~
panda728
PRO
0
180
初めてのKubernetes 本番運用でハマった話
oku053
0
130
AI駆動開発を妨げる技術的負債の解消アプローチ / ai-refactoring-approach
minodriven
17
9.3k
『コードを書く以外の』エンジニアリング〜課金基盤移行プロジェクト推進のためのTips4選
yuriko1211
0
540
吝嗇家のためのAI活用 / AI development for miser - ChatGPT + Issue Driven Development
tooppoo
0
200
改善しないと、タスクが回らない。 “てんこ盛りポジション” を引き継いだ情シスの、入社3ヶ月の業務改善録
krm963
0
190
Haskell/Servantを通してWebミドルウェアを捉え直す
pizzacat83
1
610
型も通る、synthも通る、それでも危ない 〜AIのCDKの権限とコストを機械で検証する〜 / It Passes Type Checks, It Passes Synth Checks, but It’s Still Risky — Automatically Verifying Permissions and Costs in AI’s CDK —
seike460
PRO
1
430
Prismを使った型安全な暗号化_関数型まつり2026
_fhhmm
0
150
Featured
See All Featured
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
230
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
450
BBQ
matthewcrist
89
10k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
72
40k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
180
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
Faster Mobile Websites
deanohume
310
32k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
420
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
310
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
3.9k
Transcript
知られているようで知られていない JavaScriptの仕様 4選 syumai YACP::Fukuoka *S Tech Talks (2025/11/15)
自己紹介 syumai ECMAScript 仕様輪読会 / Asakusa.go 主催 Software Design 2023年12月号から2025年2月号まで
Cloudflare Workersの連載をしました Twitter (現𝕏): @__syumai Website: https://syum.ai
カンマ演算子
カンマ演算子 , の前後に式を受け取り、後ろの式の値を演算結果とする演算子 console.log((1, 2)); // 2 console.log(((1, 2), 3));
// 3 console.log((1, (2, 3), 4)); // 4
カンマ演算子 ある変数への操作を行った直後にその値を返したい時などに使える 大体の場合は文を分ければいいので、ほぼ出番がない const f = (a) => { let
x = 0; return (x += a, x); // 変数を操作した直後に返却 }
カンマ演算子 2重配列を操作するfor文を1本で書きたい時とかに使えるらしい // 例 for (let i = 0, j
= 9; i <= 9; i++, j--) { console.log(`a[${i}][${j}] = ${a[i][j]}`); } for ( // ここは普通の変数宣言 let i = 0, j = 9; i <= 9; // ここがカンマ演算子 i++, j-- ) { console.log(`a[${i}][${j}] = ${a[i][j]}`); } https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Comma _operator#for_ループでのカンマ演算子の使用
カンマ演算子 関数オブジェクトにnameを持たせたくない時にも使える カンマ演算子を使えば、即時実行関数を使わなくていい const f1 = () => {}; //
宣言時に勝手に関数のnameに "f1" が設定される const f2 = (0, () => {}); // 式として評価してから代入しているので設定されない const f3 = (() => {})(); // 即時実行関数で評価してから代入しているので同様 console.log( f1.name, // "f1" f2.name, // "" f3.name, // "" );
direct eval / indirect eval
direct eval / indirect eval JavaScriptの世界には、2つの種類のevalがある direct eval indirect eval
これらの違いを知っていますか? function f() { let a = 0; eval("a = 1;"); // direct eval const _eval = eval; _eval("a = 2;"); // indirect eval }
direct eval / indirect eval direct evalは今のスコープを、indirect evalはグローバルスコープを操作する function f()
{ let a = 0; eval("a = 1;"); // direct eval const _eval = eval; _eval("a = 2;"); // indirect eval console.log(a); // 1 console.log(globalThis.a); // 2 }
indirect evalの入手方法 indirect evalは、 eval を一度式として評価することで入手できる カンマ演算子、optional chainなどが使える function f()
{ // いずれも indirect eval (0, eval)("a = 1;"); eval?.("b = 1;"); }
indirect eval、いつ使うのか? (そもそもユーザーが記述したコードの実行にevalは使うべきじゃない前提 で、)eval呼び出しに渡されるコードから、関数スコープの変数を見せたくない 時に使える!
Directive Prologue
この関数はstrict mode扱いになる (function() { "use strict"; with ({}) {} //
strict modeでは使えない })();
次の関数はstrict mode扱いになるか? (function() { "use not strict"; "use strict"; with
({}) {} // ? })();
答え: strict mode扱いになる
strict mode扱いになる (function() { "use not strict"; "use strict"; //
ちゃんとここのディレクティブが効く! with ({}) {} })();
Directive Prologuesの定義 Directive Prologuesは、関数、スクリプト、モジュールの冒頭に続く最長の文字列 リテラルトークンの列でしかない その途中にどんな文字列が含まれたっていい https://tc39.es/ecma262/multipage/ecmascript-language-source-code.html#sec- directive-prologues-and-the-use-strict-directive
有効なDirective Prologuesの例 (function() { "あいうえお"; 'abcde' // 明示的にセミコロンを打ったら、1行に書いてもOK "use hoge"
// セミコロンを書かなくても、自動セミコロン挿入されるのでOK "" // 空文字もOK '' // シングルクォートもOK "use strict" // これが効く! 'use fuga' // 後ろに続いててもOK with ({}) {} // strict modeなのでwith文は使えない })();
無効なDirective Prologuesの例 ディレクティブの間に文字列以外のトークンがあると、「連続した文字列リテラ ルトークン」であるという条件が満たされない (function() { "use not strict"; 1;
"use strict"; with ({}) {} // strict modeではないので、with文が使える })();
無効なDirective Prologuesの例 ` はテンプレートリテラルであって、文字列リテラルではないので、Directive Prologuesになれない (function() { `use strict`; with
({}) {} // strict modeではないので、with文が使える })();
undefined扱いのObject
typeof document.all が undefined なのに document.all === undefined が false
!?
https://developer.mozilla.org/ja/docs/Web/API/Document/all
ECMAScriptのObjectの仕様上で、 document dot all の専用の内部フィールド、 [[IsHTMLDDA]] が定義されている https://tc39.es/ecma262/multipage/additional-ecmascript-features-for-web- browsers.html#sec-IsHTMLDDA-internal-slot
typeof に、Objectに [[IsHTMLDDA]] フィールドがあるときに "undefined" という 文字列を返すオプショナルな仕様がある https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec- typeof-operator
jkr_2255さんの記事 https://qiita.com/jkr_2255/items/f9b7218d7a2b54424c12
ご清聴ありがとうございました!