更新时间:2019年01月10日15时19分 来源:传智播客 浏览次数:
| 01 02 03 04 05 06 07 08 09 10 11 12 13 14 | const f = () => {  returnnewPromise((resolve, reject) => {    setTimeout(() => {      resolve(123);    }, 2000);  });};const testAsync = async () => {  const t = await f();  console.log(t);};testAsync(); | 
| 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 | const f = () => {  returnnewPromise((resolve, reject) => {    setTimeout(() => {      resolve(123);    }, 2000);  });};const testAsync = () => {  f().then((t) => {    console.log(t);  });};testAsync(); | 
| 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 | const f = () => {  returnnewPromise((resolve, reject) => {    setTimeout(() => {      reject(234);    }, 2000);  });};const testAsync = async () => {  try{    const t = await f();    console.log(t);  } catch(err) {    console.log(err);  }};testAsync(); | 
| 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | const f1 = () => {  returnnewPromise((resolve, reject) => {    setTimeout(() => {      reject(111);    }, 2000);  });};const f2 = () => {  returnnewPromise((resolve, reject) => {    setTimeout(() => {      reject(222);    }, 3000);  });};const testAsync = async () => {  try{    const t1 = await f1();    console.log(t1);    const t2 = await f2();    console.log(t2);  } catch(err) {    console.log(err);  }};testAsync(); | 
| 1 2 3 4 5 6 7 8 | vargulp = require('gulp');varbabel = require('gulp-babel');gulp.task('babel', function() {  returngulp.src('src/app.js')    .pipe(babel())    .pipe(gulp.dest('dist'));}); |