最終更新:2022-03-08 (火) 10:30:24 (752d)
ES6/モジュール
http://exploringjs.com/es6/ch_modules.html
仕様
概要
- default export?s are favored
- Static module structure
- Support for both synchronous and asynchronous loading
- Support for cyclic dependencies between modules
サポート
- iOS Safari 10.1以上 (2017年3月リリース)
- macOS Safari 10.3以上 (2017年3月リリース)
- Chrome 61以上 (2017年8月リリース)
- Edge 16以上 (2017年10月リリース)
別名
- ES2015 Modules、ES6 Modules、ES Modules、ESM
ES6/export
名前付きexport
export var name = 'Taro'; export var age = 20; export var talk = function () { alert('I am Taro'); };
var name = 'Taro'; var age = 20; var talk = function () { alert('I am Taro'); }; export {name, age, talk};
export default
- export default <モジュール変数>
- import <変数> from 'module.js';
共通
- import talk, {hoge, fuga} from './export';
ES6/import
import {name} from 'module.js';
import {name, age, talk} from 'module.js';