ES6---Promise应用: async, await
1. k2
var k1 = new Promise((resolve, reject) => { resolve('ok'); }) console.log(k1); async function k2() { } console.log(k2);
console:
2.
var k1 = new Promise((resolve, reject) => { resolve('ok'); }) console.log(k1); async function k2() { } console.log(typeof k2);
console:
3. k2()
var k1 = new Promise((resolve, reject) => { resolve('ok'); }) console.log(k1); async function k2() { } console.log(k2());
console:
以上:k2和k2()执行后的结果不一样,前者是一个function对象,后者k2()是k2函数执行并返回的值,这个值的类型是promise
4.
var k1 = new Promise((resolve, reject) => { resolve('ok'); }) console.log(k1); //k2和k2()执行后的结果不一样,前者是一个function对象,后者k2()是k2函数执行并返回的值,这个值的类型是promise async function k2() { return 'ok2'; } console.log(k2());
console:
5.
var k1 = new Promise((resolve, reject) => { resolve('ok');//目的,是不是找人接手 }).then(result => { console.log('收到promise传过来的值:' + result); }); console.log(k1); //k2和k2()执行后的结果不一样,前者是一个function对象,后者k2()是k2函数执行并返回的值,这个值的类型是promise async function k2() { return 'ok2'; } k2().then(null); console.log(k2());
console:
6.
var k1 = new Promise((resolve, reject) => { resolve('ok');//目的,是不是找人接手 }).then(result => { console.log('收到promise传过来的值:' + result); }); console.log(k1); //k2和k2()执行后的结果不一样,前者是一个function对象 //而k2()是执行k2这个函数,并返回一个值,这个值的类型是promise async function k2() { return 'ok2'; } k2().then(result => { console.log('收到promise传过来的值:' + result); }); console.log(k2());
console: