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
150
Node.js, Deno, Bun 最新動向とその所感について
yosuke_furukawa
PRO
10
4.4k
Welcome JSConf.jp 2024
yosuke_furukawa
PRO
1
4.3k
tc39 x jsconf.jp Panel Discussion 2024
yosuke_furukawa
PRO
0
270
Removing Corepack
yosuke_furukawa
PRO
9
1.7k
JavaScript Runtime とはなにか
yosuke_furukawa
PRO
15
2.9k
Strip Types と Storage
yosuke_furukawa
PRO
4
430
Module Harmony について
yosuke_furukawa
PRO
3
1.8k
LTのやり方
yosuke_furukawa
PRO
16
2.7k
Other Decks in Programming
See All in Programming
overlayPreferenceValue で実現する ピュア SwiftUI な AdMob ネイティブ広告
uhucream
0
170
Things You Thought You Didn’t Need To Care About That Have a Big Impact On Your Job
hollycummins
0
200
デミカツ切り抜きで面倒くさいことはPythonにやらせよう
aokswork3
0
210
なぜあの開発者はDevRelに伴走し続けるのか / Why Does That Developer Keep Running Alongside DevRel?
nrslib
3
380
iOSエンジニア向けの英語学習アプリを作る!
yukawashouhei
0
190
iOSアプリの信頼性を向上させる取り組み/ios-app-improve-reliability
shino8rayu9
0
160
GraphQL×Railsアプリのデータベース負荷分散 - 月間3,000万人利用サービスを無停止で
koxya
1
1.2k
2分台で1500examples完走!爆速CIを支える環境構築術 - Kaigi on Rails 2025
falcon8823
3
3.4k
Six and a half ridiculous things to do with Quarkus
hollycummins
0
140
CSC509 Lecture 01
javiergs
PRO
1
440
Your Perfect Project Setup for Angular @BASTA! 2025 in Mainz
manfredsteyer
PRO
0
150
詳しくない分野でのVibe Codingで困ったことと学び/vibe-coding-in-unfamiliar-area
shibayu36
3
4.7k
Featured
See All Featured
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
229
22k
A Tale of Four Properties
chriscoyier
160
23k
How STYLIGHT went responsive
nonsquared
100
5.8k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
Large-scale JavaScript Application Architecture
addyosmani
514
110k
What's in a price? How to price your products and services
michaelherold
246
12k
Become a Pro
speakerdeck
PRO
29
5.5k
Building a Modern Day E-commerce SEO Strategy
aleyda
43
7.7k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Why You Should Never Use an ORM
jnunemaker
PRO
59
9.6k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
13k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
285
14k
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