| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Statements/import | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. Its been available across browsers since 2018 5.
* Some parts of this feature may have varying levels of support.
import .
**import()** , type="module" .
<script> nomodule .
import defaultExport from "module-name";
import * as name from "module-name";
import { export1 } from "module-name";
import { export1 as alias1 } from "module-name";
import { export1 , export2 } from "module-name";
import { foo , bar } from "module-name/path/to/specific/un-exported/file";
import { export1 , export2 as alias2 , [...] } from "module-name";
import defaultExport, { export1 [ , [...] ] } from "module-name";
import defaultExport, * as name from "module-name";
import "module-name";
var promise = import("module-name");
defaultExport.
module-name . , .js . , . .
name, .
exportN.
aliasN.
name export . member , name . name default export . .
. export ( ) myModule .
import * as myModule from "my-module.js";
. myMember .
import { myMember } from "my-module.js";
. foo bar .
import { foo, bar } from "my-module.js";
. shortName .
import { reallyReallyLongModuleMemberName as shortName } from "my-module.js";
.
import {
reallyReallyLongModuleMemberName as shortName,
anotherLongModuleName as short,
} from "my-module.js";
.
import "my-module.js";
default export . (object, function, class ). export import .
:
import myModule from "my-module.js";
(namespace ). , . :
import myDefault, * as myModule from "my-module.js";
// myModule used as a namespace
import myDefault, { foo, bar } from "my-module.js";
// specific, named imports
AJAX JSON .
// --file.js--
function getJSON(url, callback) {
let xhr = new XMLHttpRequest();
xhr.onload = function () {
callback(this.responseText);
};
xhr.open("GET", url, true);
xhr.send();
}
export function getUsefulContents(url, callback) {
getJSON(url, (data) => callback(JSON.parse(data)));
}
// --main.js--
import { getUsefulContents } from "file.js";
getUsefulContents("http://www.example.com", (data) => {
doSomethingUseful(data);
});
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-imports |
exportThis page was last modified on 2024 12 17 by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |