index.js // var num = 1;function readFile (path) { return (cb) => { fs.readFile(path , 'utf8' , cb) }}co( function* () { var a = yield readFile('./index.js'); console.log(a); var b = yield readFile('./index.js'); console.log(b); var c = yield readFile('./index.js'); console.log(c);}).catch((e) => {})主要不明白得地方 是 a,b,c 為什么會是 readFile index.js中的內(nèi)容?readFile的返回值 是一個函數(shù)呀,yield 也只是等這個異步函數(shù)執(zhí)行完成,在執(zhí)行下一步呀;
generator 函數(shù)
海綿寶寶撒
2019-03-04 17:55:13