如何理解異步處理?什么時(shí)候使用?
this.book.ready.then(()?=>?{???? ??return?this.book.loacations.generate() }).then(res?=>?{? ?console.log(res) ?this.locations?=?this.book.loacations
()?=>
res?=>
這兩個(gè)又有什么區(qū)別呢?
this.book.ready.then(()?=>?{???? ??return?this.book.loacations.generate() }).then(res?=>?{? ?console.log(res) ?this.locations?=?this.book.loacations
()?=>
res?=>
這兩個(gè)又有什么區(qū)別呢?
2019-02-17
舉報(bào)
2019-03-04
這個(gè)問(wèn)題有點(diǎn)大,你需要了解的知識(shí)點(diǎn)是:
1,js為什么要設(shè)計(jì)為單線程,單線程的優(yōu)點(diǎn)及缺點(diǎn),引出異步的概念
2,了解eventloop機(jī)制,弄清楚異步函數(shù)是如何執(zhí)行的
3,更深入了解的話異步又分macrotask和microtask.其中promise方法屬于microtask.這里的this.book.ready.then顯然就是promise對(duì)象.
4,此時(shí)你得好好研究promise對(duì)象.這是es6里非常重要的對(duì)象
5,在研究過(guò)程中你會(huì)看到很多()=>{}這樣的箭頭函數(shù),這也是es6里的新內(nèi)容.
到此這個(gè)問(wèn)題應(yīng)該能解決了.(這5點(diǎn)都是長(zhǎng)篇大論需要花時(shí)間去琢磨)