Basic es module knowledge, deep understanding

Source: Internet
Author: User
// Basic knowledge of a module/*** export: used to export the module * import: file import entry * // 1, first, use the export method to output var A = 'a'; var B = 'V'; export {a, B}; // 2, use export as the default output export {A as streamv1, B as streamv2}; // 3. The export can be at any position, as long as it is at the top, cannot be in block-level scope/*** import file module loading * // 1. Directly load import {a, B} from 'in the module '. /ass '; // 2. The module outputs import * as cricle from' directly '. /ass 'cricle. A // A/*** export default output command, import module loading, no {} module loading ** // 1. Anonymous functions are directly used, import can be directly loaded by the module, and the output name export default function () {console. log ('foo');} import customname from '. /export-default '; // 2, directly output function add (x, y) {return x * Y ;}
Export {Add as default} // directly equivalent to export default add;
Import {default as Foo} from '. /add'; import Foo from '. /modules '/*** combination of export and import */export {Foo, bar} from '. /my_module '; // It can be simply understood as import {Foo, bar} from '. /my_module '; export {Foo, bar}; // 2. Export List export {detectcats, kittydar}; // No 'export' keyword required here function detectcats (canvas, options) {...} class kittydar {...} // 3. Rename Export and Import {flip as flipomelet} from "eggs. JS "; import {flip as fliphouse} from" real-estate.js"
Function V1 () {...} function V2 (){...}
Export {v1 as streamv1, v2 as streamv2, v2 as streamlatestversion}; // 4. Default Import and Export
Import colors from "Colors/safe"; export default {field1: value1, field2: value2 };
// Module object, such as namespace
Import * as cows from "cows ";
// The aggregation module. It does not bind the export {tea, cinnamon} from "Sri-Lanka" variable to be exported to the current scope ";
/*** Understanding es6 module mechanism https://zhuanlan.zhihu.com/p/33843378? Group_id = 947910338939686912 */

Basic es module knowledge, deep understanding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.