Saturday, October 1, 2022

Javascript Dynamic Import

Javascript Dynamic Import 

The import() call, commonly called dynamic import, is a function-like expression that allows loading an ECMAScript module asynchronously and dynamically into a potentially non-module environment.

(async () => {

  if (somethingIsTrue) {

    // import module for side effects

    await import("/modules/my-module.js");

  }

})();

Importing defaults

(async () => {

  if (somethingIsTrue) {

    const {

      default: myDefault,

      foo,

      bar,

    } = await import("/modules/my-module.js");

  }

})();


references:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import

No comments:

Post a Comment