π λͺ¨λ : νμΌμ μͺΌκ°μ 보κ΄ν¨μΌλ‘μ¨ μ½λμ μ¬νμ©μ±κ³Ό μ μ§λ³΄μλ₯Ό μ½κ² ν μ μλλ‘ νλ€.
math.js
export const plus = (a,b) => a+b;
export const minus = (a,b) => a-b;
export const divide = (a,b) => a/b;
main.js
import { plus, minus, divide } from './math';
plus(2,3);
minus(2,3);
divide(2,3);
main.js ('as'ν€μλ μ¬μ©)
import { plus as add } from './math';
plus(2,3);
minus(2,3);
divide(2,3);
math.js
const plus = (a,b) => a+b;
const minus = (a,b) => a-b;
const divide = (a,b) => a/b;
export default { plus, minus, divide }
main.js
import math from './math';
math.plus(2,3);
db.js
const connnectToDB = () => { abc };
export const getUrl = () => { 111 };
export default connectToDB;
main.js
import connect, { getUrl } from './db';
math.js
export const plus = (a,b) => a+b;
export const minus = (a,b) => a-b;
export const divide = (a,b) => a/b;
main.js
import * as myMath from './math';
myMath.plus(2,2);
λ³κ²½μ
function doMath() {
import('./math)
.then(math => math.plus(2,2));
}
btn.addEventListener('click', doMath);
λ³κ²½ν
async function doMath() {
const math = await import('./math');
math.plus(2,2);
}
btn.addEventListener('click', doMath);