Ez a fordítás hiányos. Segítsen a cikk angolról történő lefordításában

The import statement is used to import functions that have been exported from an external module, another script, etc.

Megjegyzés: Ez a funkció még lett implementálva semmilyen böngészőben ezidáig, viszont több transpiler is implementálta például Traceur Compiler és a ES6 Module Transpiler.


import name from "module-name";
import { member } from "module-name";
import { member as alias } from "module-name";
import { member1 , member2 } from "module-name";
import { member1 , member2 as alias2 , [...] } from "module-name";
import name , { member [ , [...] ] } from "module-name";
import "module-name";
Az objektum neve ami az importált értékeket megkapja.
member, memberN
A modul által exportálát tagok közül melyek legyenek importálva (azonos névvel)
alias, aliasN
A modul által exportálát tagok közül melyek legyenek importálva és milyen névvel
Az importálandó modul neve. Ez egy fájlnév.


The name parameter is the name of the object that will receive the exported members. The member parameters specify individual members, while the name parameter imports all of them. name may also be a function if the module exports a single default parameter rather than a series of members. Below are examples to clarify the syntax.

Import an entire module's contents. This inserts myModule into the current scope, containing all the exported bindings.

import myModule from "my-module.js";

Import a single member of a module. This inserts myMember into the current scope.

import {myMember} from "my-module.js";

Import multiple members of a module. This inserts both foo and bar into the current scope.

import {foo, bar} from "my-module.js";

Import an entire module's contents, with some also being explicitly named. This inserts myModulefoo, and bar into the current scope. Note that foo and are the same, as are bar and

import MyModule, {foo, bar} from "my-module.js";

Import a member with a more convenient alias. This inserts shortName into the current scope.

import {reallyReallyLongModuleMemberName as shortName} from "my-module.js";

Import an entire module for side effects only, without importing any bindings.

import "my-module.js";


Importing a secondary file to assist in processing a AJAX JSON request.

// --file.js--
function getJSON(url, callback) {
  let xhr = new XMLHttpRequest();
  xhr.onload = function () { 
  };"GET", url, true);

export function getUsefulContents(url, callback) {
  getJSON(url, data => callback(JSON.parse(data)));

// --main.js--
import { getUsefulContents } from "file.js";
getUsefulContents("", data => {


Specification Status Comment
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Imports' in that specification.
Standard Initial definition.

Browser compatibility

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support No support[1] No support[2] No support No support No support
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support No support No support No support No support No support No support

[1] Partial support is behind a command line flag: --harmony-modules. See this V8 bug.
[2] See this Firefox bug.

Firefox-specific notes

The import and export statements were formerly an ancient feature in Netscape, but it never gained popularity in that time and have been removed in Firefox 3.5 (bug 447713).

See also