Upgrade to Pro — share decks privately, control downloads, hide ads and more …

modernweb 2017

CypressKuo
September 20, 2017

modernweb 2017

心得分享

CypressKuo

September 20, 2017
Tweet

More Decks by CypressKuo

Other Decks in Technology

Transcript

  1. Call Stack Web Apis Callback Queue http://latentflip.com/loupe Anonymous() Anonymous() Anonymous()

    Anonymous() Anonymous() Anonymous() Anonymous() Anonymous() Console.log(i)
  2. Generator + co library • 暫時交出執⾏行行權 • 封裝非同步任務,處理理 Promise •

    邏輯清楚好理理解 • 讓 Generator ⾃自動執⾏行行 https://github.com/tj/co
  3. Async & Await • 結合 Promise 與 Generator + co

    • 不需要第三⽅方套件 • 將非同步化程式同步化 • 直覺性的邏輯思考 • ES7, TypeScript, Node 7.6 ⽀支援
  4. Async & Await • async - 標著在 function 前⾯面 •

    await - 標著在 promise 前⾯面 • ⼀一定要⽤用 function 包裝
  5. Reference • http://s.itho.me/modernweb/2017/day2/403-3-陳⼩小風.pdf • https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/ Promise • https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Statements/ async_function •

    https://medium.com/@peterchang_82818/javascript-es7-async-await-教 學-703473854f29-tutorial-example-703473854f29 • https://jigsawye.com/2016/04/18/understanding-javascript-async-await/ • https://mlwmlw.org/2016/03/es7-的-async-await-入⾨門/ • https://noootown.wordpress.com/2016/11/13/callback-promise-fetch-yield-async- await/