ES6 -- 從callback到Generator、Promise, 再到ES7的Async -- Part 4/5

這篇說明javascript asynchronous programming: promises vs generators

http://stackoverflow.com/questions/28031289/javascript-asynchronous-programming-promises-vs-generators


這篇的範例碼我覺得不用深究,  因為試過好像跑不出來, 但觀念方面可以看看,


擷取我覺得值得看的地方:

1. There is no opposition between these two techniques. They coexist together complementing each other nicely.

2. Promises give you capability to get result of an asynchronous operation which does not available yet.

3. But even with promises you must write code in asynchronous fashion - you must always pass callbacks to the functions. Writing asynchronous code is much harder then synchronous.

4. So we want to write asynchronous code in synchronous fashion. That's where generators are coming to help us.



最後, 回答中有推薦一個短片, 有時間可參考一下...

Netflix JavaScript Talks - Version 7: The Evolution of JavaScript

https://www.youtube.com/watch?v=DqMFX91ToLw



留言

熱門文章