default
import CaesarCipher from 'modules/caesar.js'
import CC from 'modules/caesar.js'
import
without importing anything, just to execute the module body:
import 'app/init.js'
import { encrypt, decrypt } from 'modules/caesar.js'
import { encrypt } from 'modules/caesar.js'
import { encrypt as caesarEncrypt, decrypt as caesarDecrypt } from 'modules/caesar.js'
import * as CaesarCipherTools from 'modules/caesar.js'
CaesarCipherTools.encrypt
, CaesarCipherTools.decrypt
import CaesarCipher, { encrypt, decrypt } ... import CaesarCipher, { encrypt as caesarEncrypt, decrypt as caesarDecrypt} ... import CaesarCipher, * as CaesarCipherTools ...
import
yields a promise that is fulfilled when the module is loaded:
import(`plugins/${action}.js`) .then(module => { module.feature(args) ... })
async
function:
const module = await import(`plugins/${action}.js`)
super
export default
export default class Cipher { ... }
export default
export default class { // No need to name it if you don't want to encrypt(key) { ... } decrypt(key) { ... } }
export
:
export const defaultKey = 3 export function encrypt(key) { ... } export class KeyGenerator { ... }
const defaultKey = 3 function encrypt(key) { ... } class KeyGenerator { ... } ... export { defaultKey, encryt, KeyGenerator }
export { randInt, randDouble } from 'modules/random.js' export { randInt as randomInteger } from 'modules/random.js' export * from 'modules.random.js'
export { default } from 'modules/stringutil.js' export { default as StringUtil } from 'modules/stringutil.js'
export { Random as default } from 'modules/random.js'
<script type="module" src="modules/caesar.js"></script>
mjs
extension, package.json
"type": "module"
, --input-type=module
import
/export
are always at top level to facilitate static analysis
export
exports variables, not values.
import.meta
—metadata for the current module, such as its source URL.