JavaScript學習,export和import
Exports
定義
The
export
statement is used when creating JavaScript modules to export functions, objects, or primitive values from the module so they can be used by other programs withimport
statement.Exported modules are in
strict mode
whether you declare them as such or not. The export statement cannot be used in embeded scripts.
當創建JavaScript模型時,從模塊中去導出函數,對象,或原始值,這個
export
聲明被使用,以便他們能被其他程序用import
聲明來使用。導出的模塊是在嚴格模式下的,無論你如這樣聲明他們或不。這個export表達式不能被用在嵌套的腳本里。
語法
- 被命名的Exports(每個模塊0個或者更多的exports)
- 默認的Exports(每個模塊1個)
- 混合Hybrid Exports
Imports
Exports and Imports
代碼傳到github上去了,js-exports-import-examples