The `import()` Syntax of ES2020 Looks Promising; How to Detect if Such Feature Available Then?
Taufik Nurrohman
Posted on June 20, 2020
With the plan,
import()
is proposed to work in both modules and scripts, giving script code an easy asynchronous entry point into the module world and allowing it to start running module code.https://www.infoworld.com/article/3538809/ecmascript-2020-spec-for-javascript-approved.amp.html
Can I check the existence of this feature as it was a function? And if that is possible, is it conform to the standard?
What I am thinking:
if ('function' === typeof import) {
import('taufik-nurrohman/f3h.js').then(F3H => {
let f3h = new F3H;
});
}
Also, how do I expose module in the file to import, without causing syntax errors in the window
environment?
// :|
if ('function' === typeof import) {
export default F3H;
} else {
window.F3H = F3H;
}
Thanks!
đ đȘ đ
đ©
Taufik Nurrohman
Posted on June 20, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
undefined Building Chat With PDF from Scratch with advanced AI/ML API and Pinecone leading vector database
November 29, 2024