Skip to content

Instantly share code, notes, and snippets.

@modster
Last active January 5, 2023 23:20
Show Gist options
  • Save modster/53ad4e3e1011a6d3fba5ee31a59d32bd to your computer and use it in GitHub Desktop.
Save modster/53ad4e3e1011a6d3fba5ee31a59d32bd to your computer and use it in GitHub Desktop.
The import() expression | JAVASCRIPT
<!doctype html>
<script>
async function load() {
let say = await import('./say.js');
say.hi(); // Hello!
say.bye(); // Bye!
say.default(); // Module loaded (export default)!
}
</script>
<button onclick="load()">Click me</button>
export function hi() {
alert(`Hello`);
}
export function bye() {
alert(`Bye`);
}
export default function() {
alert("Module loaded (export default)!");
}
@modster
Copy link
Author

modster commented Jan 5, 2023

Import(module); Returns a promise which fulfills to an object containing all exports from moduleName, with the same shape as import * as name from moduleName, e.g. a sealed object with null prototype. All keys are enumerable in lexicographic order (i.e. the default behavior of Array.prototype.sort()), with the default export available as a key called default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment