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
1k
mjs
We are JavaScripters で発表した .mjs の話です。
Yosuke Furukawa
PRO
April 24, 2018
Tweet
Share
More Decks by Yosuke Furukawa
See All by Yosuke Furukawa
tc39 x jsconf.jp Panel Discussion 2024
yosuke_furukawa
PRO
0
130
Removing Corepack
yosuke_furukawa
PRO
9
1.2k
JavaScript Runtime とはなにか
yosuke_furukawa
PRO
15
2.4k
Strip Types と Storage
yosuke_furukawa
PRO
4
330
Module Harmony について
yosuke_furukawa
PRO
3
1.5k
LTのやり方
yosuke_furukawa
PRO
16
2.1k
AppRouter Panel Talk
yosuke_furukawa
PRO
3
690
Node.js v22 で変わること
yosuke_furukawa
PRO
13
5.2k
リアーキテクトと開発生産性について
yosuke_furukawa
PRO
25
9.5k
Other Decks in Programming
See All in Programming
Nuxt UI Pro、NuxtHub、Nuxt Scripts、Nuxtエコシステムをふんだんに利用して開発するコーポレートサイト@Vue Fes Japan 2024
shingangan
3
880
RailsのPull requestsのレビューの時に私が考えていること
yahonda
5
1.7k
役立つログに取り組もう
irof
26
8.6k
Mastering Dependencies in Kotlin Multiplatform
tomifabian
0
110
推し活としてのrails new/oshikatsu_ha_iizo
sakahukamaki
3
1.6k
Amazon Neptuneで始めてみるグラフDB-OpenSearchによるグラフの全文検索-
satoshi256kbyte
4
310
Importmapを使ったJavaScriptの 読み込みとブラウザアドオンの影響
swamp09
4
1.2k
組織に自動テストを書く文化を根付かせる戦略(2024秋版) / Building Automated Test Culture 2024 Autumn Edition
twada
PRO
10
4.5k
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
23k
/←このスケジュール表に立ち向かう フロントエンド開発戦略 / A front-end development strategy to tackle a single-slash schedule.
nrslib
1
590
VR HMDとしてのVision Pro+ゲーム開発について
yasei_no_otoko
0
100
offers_20241022_imakiire.pdf
imakurusu
2
360
Featured
See All Featured
Adopting Sorbet at Scale
ufuk
73
9k
The World Runs on Bad Software
bkeepers
PRO
65
11k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
664
120k
Speed Design
sergeychernyshev
24
570
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Six Lessons from altMBA
skipperchong
26
3.5k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
167
49k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Designing for humans not robots
tammielis
249
25k
Statistics for Hackers
jakevdp
796
220k
Why Our Code Smells
bkeepers
PRO
334
57k
Build The Right Thing And Hit Your Dates
maggiecrowley
32
2.4k
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