ES6 Learning--modularization: module Loader API

Source: Internet
Author: User
Tags export class es6 class

In the last chapter, the modular API is a static import process, that is, it is not possible to import some other modules dynamically according to the program logic. There is a dynamically imported API in the draft phase of the ES6 specification, but it was removed when the ES6 formal specification came out, you can refer to Https://github.com/ModuleLoader/es6-module-loader, Personally think this API is still very useful, so here is a brief introduction.

In fact, this API is very simple, based on promise mode:

Mymodule.js
Export Class Q {
    constructor () {
      Console.log (' This is a es6 class! ');
    }
  

<script>
  system.import (' MyModule '). Then (function (m) {
    new m.q ();
  });
</script>

You can also implement dynamic import using the script label for module with type:

<script type= "module" >
  //Loads the ' Q ' Export from ' mymodule.js ' same path as the page
  import {q} From ' MyModule ';

  New Q (); -> ' This is a es6 class! '
</script>

If you want to know more, you can go to the GitHub and study carefully.


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.