javascript import as code example
Example 1: alias import javascript
import {default as alias} from 'my-module';
Example 2: javascript import class
import Example from './file2';
var myInstance = new Example()
myInstance.test()
Example 3: js es6 dynamic import default
export const hi = (name) => console.log(`Hi, ${name}!`)
export const bye = (name) => console.log(`Bye, ${name}!`)
export default () => console.log('Hello World!')
We can use import() syntax to easily and cleanly load it conditionally:
if (somethingIsTrue) {
import('./something.js').then((module) => {
module.hi('Erick')
module.bye('Erick')
module.default()
})
}
Example 4: javascript import
import { module } from "./path";
import Module from "./path";
import Module, { module } from "./path";
Example 5: import javascript
import { add } from './math_functions.js';
import { add, someothervariable } from './math_functions.js';
Example 6: javascript import
"type": "module",
import { module } from "./path";