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
mjs
Search
Yosuke Furukawa
PRO
April 24, 2018
Programming
4
1.1k
mjs
We are JavaScripters で発表した .mjs の話です。
Yosuke Furukawa
PRO
April 24, 2018
Tweet
Share
More Decks by Yosuke Furukawa
See All by Yosuke Furukawa
デザインシステムが必須の時代に
yosuke_furukawa
PRO
2
210
Node.js, Deno, Bun 最新動向とその所感について
yosuke_furukawa
PRO
10
5k
Welcome JSConf.jp 2024
yosuke_furukawa
PRO
1
4.6k
tc39 x jsconf.jp Panel Discussion 2024
yosuke_furukawa
PRO
0
300
Removing Corepack
yosuke_furukawa
PRO
9
1.9k
JavaScript Runtime とはなにか
yosuke_furukawa
PRO
15
3k
Strip Types と Storage
yosuke_furukawa
PRO
4
480
Module Harmony について
yosuke_furukawa
PRO
4
1.8k
LTのやり方
yosuke_furukawa
PRO
16
2.9k
Other Decks in Programming
See All in Programming
SourceGeneratorのマーカー属性問題について
htkym
0
160
クライアントワークでSREをするということ。あるいは事業会社におけるSREと同じこと・違うこと
nnaka2992
1
310
The Ralph Wiggum Loop: First Principles of Autonomous Development
sembayui
0
3.7k
encoding/json/v2のUnmarshalはこう変わった:内部実装で見る設計改善
kurakura0916
0
330
go directiveを最新にしすぎないで欲しい話──あるいは、Go 1.26からgo mod initで作られるgo directiveの値が変わる話 / Go 1.26 リリースパーティ
arthur1
2
470
エージェント開発初心者の僕がエージェントを作った話と今後やりたいこと
thasu0123
0
230
Fundamentals of Software Engineering In the Age of AI
therealdanvega
1
210
社内規程RAGの精度を73.3% → 100%に改善した話
oharu121
13
7.6k
あなたはユーザーではない #PdENight
kajitack
4
300
Go Conference mini in Sendai 2026 : Goに新機能を提案し実装されるまでのフロー徹底解説
yamatoya
0
520
今更考える「単一責任原則」 / Thinking about the Single Responsibility Principle
tooppoo
3
1.5k
JPUG勉強会 OSSデータベースの内部構造を理解しよう
oga5
2
240
Featured
See All Featured
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
1
460
How to Think Like a Performance Engineer
csswizardry
28
2.5k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.3k
My Coaching Mixtape
mlcsv
0
64
From π to Pie charts
rasagy
0
150
Into the Great Unknown - MozCon
thekraken
40
2.3k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.1k
The untapped power of vector embeddings
frankvandijk
2
1.6k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
96
For a Future-Friendly Web
brad_frost
183
10k
Designing for Timeless Needs
cassininazir
0
150
Claude Code のすすめ
schroneko
67
220k
Transcript
.mjs 2018/04/24 We are JavaScripters!! @ Recruit Technologies
Twitter: @yosuke_furukawa Github: yosuke-furukawa
Node.js v10 Release (maybe tomorrow)
Node.js v10 Notable Changes • for-await-of in Stream experimental
support • ESModules experimental support • private/public class fields experimental support • fs/promises
DEMO
DEMO import fs from 'fs/promises'; import util from 'util'; async
function main() { try { const content = await fs.readFile(process.argv[2]) console.log(content.toString()) } catch(e) { console.error(e.toString()); } } main();
file name is … foo.mjs
ʊʊਓਓਓʊʊ ʼɹ.mjs !!!ɹʻ ʉʉY^Y^Yʉʉ
Yes, we have long discussion about ESM.
We need ".mjs".
Why?
Module !== Script
Module [ "strict", "top level scope", "reserved await" ] Script
[ "non strict", "global scope", ]
We need to detect which mode on load file.
if file.lastIndexOf(".mjs") { Module } else { Script }
Simple and Faster
We do not use ".js" ???? (´ɾωɾʆ)
No, 2 reasons.
Use loader option.
DEMO
DEMO const builtins = Module.builtinModules; const URL = url.URL; const
baseURL = new URL('file://'); baseURL.pathname = `${process.cwd()}/`; export function resolve(specifier, parentModuleURL = baseURL, defaultResolve) { if (builtins.includes(specifier)) { return { url: specifier, format: 'builtin' }; } const resolved = new url.URL(specifier, parentModuleURL); const ext = path.extname(resolved.pathname); return { url: resolved.href, format: 'esm' }; }
DEMO $ node —experimental-modules —loader loader.mjs file.js // file.js import
fs from 'fs'; import util from 'util'; const readFile = util.promisify(fs.readFile); async function main() { try { const content = await readFile(process.argv[2]) console.log(content.toString()) } catch(e) { console.error(e.toString()); } } main();
mode detection on flag `—mode` , package.json see: https://gist.github.com/ceejbot/b49f8789b2ab6b09548ccb72813a1054
https://docs.google.com/presentation/d/ 1xK1ana_TIxfAHX33CYVHFnJsV0If_YirLtRBBga9cv0/edit#slide=id.p
You just use ".js" if you don’t need to use
ESM.
You would be better to use ".mjs", if you need
ESM on Node.js v9-10.
You would be better to wait the conclusion, if you
want to use ES Modules in the future.
ऄ (da-soku) +
Filename Extensions YOMO-YAMA
Long long time ago… Brendan Eich saids …
)PXEPXFUIJOLFT FTpMFFYUFOTJPOTUPEFUFDU WFSTJPOT // sorry no reference… I cannot find
link 8FOFFEUPDIBOHFpMFOBNFFYUFOTJPOTUPVQHSBEF UIBUJTOJHIUNBSFʜ
*EJTMJLFNPEFT8IPEPFTOU #VUUIJTTPVOETMJLF UIF7FSTJPOJOHJTBOBOUJQBUUFSOTIJCCPMFUI*WF IFBSESFDFOUMZSF8FC4PDLFUT*UEPFTOPUSFqFDU SFBMJUZ https://esdiscuss.org/topic/no-more-modes 3FDFOUMZ *NFUXJUIUIF(PPHMF7UFBNGPSUXPGVMM EBZT0OFNFTTBHFUIBUDBNFUISPVHIMPVEBOE DMFBS
UIBU*TBJE*XPVMESFMBZUPUIFMJTU JTQMFBTF OPNPSFNPEFT
Web does not have version/mode.
All we need is feature detection.
Detectable Feature // Feature Detection if (!Array.isArray) {} if (!String.prototype.trimStart)
{}
un-detectable feature (on runtime) class A {} import / export
#foo // syntax
Modern JavaScript is difficult to detect features.
Module JavaScript is JavaScript 2.0
JavaScript is not so easy, We are JavaScripters, Every JSers
would be better to enjoy chaos.
Enjoy JS Chaos :)
Thanks