| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/import | [Back] [Original] |
Get to know MDN better
import(moduleName)
import(moduleName, options)
import() import const myImport = import SyntaxError
:
import()
import (import something from "somewhere") import
eval HTML script type="module" import import
import("./data.json", { with: { type: "json" } });
2 (import * as name from moduleName)
nullArray.prototype.sort() default [Symbol.toStringTag] "Module" Object.prototype.toString()
Object.getOwnPropertyDescriptors() - -
import * as mod from "/my-module.js";
import("/my-module.js").then((mod2) => {
console.log(mod === mod2); // true
});
1 thenable my-module.js then()
// my-module.js
export function then(resolve) {
console.log("then() called");
resolve(1);
}
// main.js
import * as mod from "/my-module.js";
import("/my-module.js").then((mod2) => {
// Logs "then() called"
console.log(mod === mod2); // false
});
:
then()
JavaScript HTTP JavaScript URL
import(`/my-module.js?t=${Date.now()}`);
blob: URL Node.js vm.Module JSON.parse() CSSStyleSheet replace() 3 HTTP fetch()
(async () => {
if (somethingIsTrue) {
//
await import("/modules/my-module.js");
}
})();
ESM
default default
(async () => {
if (somethingIsTrue) {
const {
default: myDefault,
foo,
bar,
} = await import("/modules/my-module.js");
}
})();
import() await
const main = document.querySelector("main");
for (const link of document.querySelectorAll("nav > a")) {
link.addEventListener("click", (e) => {
e.preventDefault();
import("/modules/my-module.js")
.then((module) => {
module.loadPageInto(main);
})
.catch((err) => {
main.textContent = err.message;
});
});
}
document navigator API
let myModule;
if (typeof window === "undefined") {
myModule = await import("module-used-on-server");
} else {
myModule = await import("module-used-in-browser");
}
/modules/module-0.js/modules/module-1.js 10 load
Promise.all(
Array.from({ length: 10 }).map(
(_, index) => import(`/modules/module-${index}.js`),
),
).then((modules) => modules.forEach((module) => module.load()));
const data = await import("./data.json", {
with: { type: "json" },
});
| ECMAScript 2027 LanguageSpecification # sec-import-calls |
| Web Proxy Viewer | New URL | Original Page |