es6 模块化

es6 模块化

2  es6 模块化

import 有提升效果, 在引入语句之前可以访问成功

import 的模块是否需要{} 花括号

default可以不使用花括号 

export 需要{}   export default 不需要  {}

es6 模块化

3   模块按需加载

上面的模块加载方式是不允许写在if语句中, 也就是按需加载

es6 模块化

4  类(class)和 继承

es6 模块化

 

es6 模块化

 

es6 模块化

 

实现异步调用的几种方式

1  generator  手动调用, 比较麻烦   返回的是一个对象   {value:XX , done:XX}

2  promise  使得回调函数的写法更优雅 

new  Promise(function(resolve, reject){}).then(function(){

console.log('成功了');

}).catch(err=>{

console.log('失败了');

})

3  async   await    语义明确 , 更建议使用

 

es6 模块化

async   和  await

 

es6 模块化

es6 模块化

es6 模块化

es6 模块化

es6 模块化