[JS]: import/export snippets
JS
09/26/2019
Export
Default Export
person.js
JS
export default const person = { name: "Ellis",}
// ORconst person = { ... }export default person
Named Export
util.js
JS
export const func1 = () => { ... }export const func2 = () => { ... }
// ORconst fun1 = () => { ... }const fun2 = () => { ... }export = { func1, func2 }
Import
JS
import p from "./person.js" // Can assign any name for named export
// Must use the same name assigned in util.js but can assign aliasimport { func1, func2 } from "./util.js"
alias
JS
import { func1 as firstFcn, func2 as secondFcn } from "./util.js"
*
JS
// Usage: functions.func1 / functions.func2import * as functions from "./util.js"