Last active
January 5, 2023 23:20
-
-
Save modster/53ad4e3e1011a6d3fba5ee31a59d32bd to your computer and use it in GitHub Desktop.
The import() expression | JAVASCRIPT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function hi() { | |
alert(`Hello`); | |
} | |
export function bye() { | |
alert(`Bye`); | |
} | |
export default function() { | |
alert("Module loaded (export default)!"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Import(module);
Returns a promise which fulfills to an object containing all exports frommoduleName
, with the same shape asimport * as name from moduleName
, e.g. a sealed object with null prototype. All keys are enumerable in lexicographic order (i.e. the default behavior ofArray.prototype.sort())
, with the default export available as a key calleddefault
.