ES6学习——模块化:Module Loader API
2016-02-07 19:06
549 查看
上篇讲的模块化API总体来讲是个静态导入的过程,就是不能根据程序逻辑动态的导入一些其他模块。在ES6规范的草案阶段有个动态导入的API,但是在ES6正式规范出来的时候被去掉了,大家可以参考https://github.com/ModuleLoader/es6-module-loader,个人觉得这个API还是很有用的,所以这里介绍一下。
其实这个API很简单,基于Promise模式:
还可以使用type为module的script标签实现动态导入:
想深入了解的可以自己去那个github仔细学习学习
其实这个API很简单,基于Promise模式:
//mymodule.js export class q { constructor() { console.log('this is an es6 class!'); } }
<script> System.import('mymodule').then(function(m) { new m.q(); }); </script>
还可以使用type为module的script标签实现动态导入:
<script type="module"> // loads the 'q' export from 'mymodule.js' in the same path as the page import { q } from 'mymodule'; new q(); // -> 'this is an es6 class!' </script>
想深入了解的可以自己去那个github仔细学习学习
相关文章推荐
- Unity在编辑器状态下清空控制台信息
- 用Instruments 简单分析内存
- 使用malloc()结果的两种方式
- Android对话框自定义标题
- VB脚本编写的小题库程序
- Codeforces Round #256 (Div. 2)总结
- POJ 3070 矩阵的幂
- LightOJ 1028 1028 - Trailing Zeroes (I) (求因子个数)
- 2016
- 单例
- Java基础练习 字母图形
- Docker对于部署来说及其重要
- 云计算的基础概念
- Hadoop内部的限流机制
- C#读写文本文件并导入Excel(二)
- 大数据 IMF 传奇 spark -history在分布式 集群 的安装部署 及问题解决
- 文件系统访问列表
- 第十六天
- Python爬虫基础实例教程
- BZOJ 1653 USACO 2006 Feb Backward Digit Sums 全排列