console.log(this) 特性2:每个 ES module 都是运行在单独的私有作用域中 ..._浏览器esm特性">
赞
踩
目录
四、ES Modules in Node.js - 支持情况
五、 ES Modules in Node.js - 与 CommonJS 交互
六、ES Modules in Node.js - 与 CommonJS 的差异
七、ES Modules in Node.js - 新版本进一步支持
八、 ES Modules in Node.js - Babel 兼容方案
一、ES Modules 特性
- <script type="module">
- console.log(this)
- </script>
- <script type="module">
- var foo = 100
- console.log(foo) //100
- </script>
- <script type="module">
- console.log(foo) //找不到
- </script>
<script type="module" src="https://unpkg.com/jquery@3.4.1/dist/jquery.min.js"></script>
二、ES Modules 导出
-
- import { name, hello, Person } from './module.js'
- console.log(name, hello, Person)
-
- import { name } from './module.js' //不能省略 .js
-
- import { name } from './module.js' //不能省略 ./
- import { name } from '04-import//module.js'
-
- import { } from './module.js' //只是导出模块,并不会提取成员
- import './module.js'
-
- import * as mod from './module.js' //导出所有成员
-
- import('./module.js').then(function (modile) { //动态导入模块
- console.log(modile)
- })
-
- import { name, age, default as title } from './module.js' //导出默认成员
- import title, { name, age } from './module.js'
- //index.js
- export { default as button } from './button.js'
- export { Avatar } from './avatar.js'
-
- //button.js
- export var BUtton = 'Button Component'
-
- export default Button
-
- //avatar.js
- export var Avatar = '
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。