Javascript - Export

> (World Wide) Web - (W3|WWW) > Javascript (Js|ECMAScript) > ECMAScript - Grammar Standard > Javascript ES - Module Script

1 - About

The export statement is the counterpart of the import statement in the implementation of an ES module.

It has the same functionality that the modules.export statement of CommonfJs

This feature is not implemented in any browsers natively at this time. It is implemented in many transpilers.

Export declare the module’s public API.

Advertising

3 - Syntax

You can export any top-level function, class, var, let, or const.

4 - Syntax

4.1 - Export tag

export function bar(arg1, arg2) {
}
 
export class foo {
  ... several methods doing image processing ...
}
 
// This function isn't exported and has then a local scope
function private() {
  ...
}

4.2 - Export lists

Rather than tagging each exported feature, you can write out a single list of all the names you want to export. It can appear anywhere in a module file’s top-level scope

export {foo, bar};

4.3 - Default

let myObject = {
  field1: value1,
  field2: value2
};
export {myObject as default};
  • Shorthand where the keywords export default can be followed by any value: a function, a class, an object literal, …
 export default {
  field1: value1,
  field2: value2
};
web/javascript/es/module/export.txt · Last modified: 2019/03/19 09:24 by gerardnico