























歷史上,JavaScript 沒有 module 的體系,無法將一個大程序拆分成互相依賴的小模組在用更簡單的方式拼湊起來。
requireimport@import在一個檔案內 export default 只能有一個,而 export 可以有多個
如果只透過 export 時,在 import 必須加入花刮號 {} 來導入
兩者都可以導入常量、函數、檔案、模組
// app.js
export const str = "hello world";
export function log(sth) {
return sth;
}
對應的導入方式
import { str, log } from 'app'
// app.js
const str = "hello world";
export default str;
對應的導入方式
import str from 'app';
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。