{"id":21479409,"url":"https://github.com/meathill/gitbook-javascript-async-tutorial","last_synced_at":"2025-07-15T11:31:40.108Z","repository":{"id":51401573,"uuid":"97355887","full_name":"meathill/gitbook-javascript-async-tutorial","owner":"meathill","description":"A full tutorial for JavaScript asynchronous development, with every new feature.","archived":false,"fork":false,"pushed_at":"2021-05-12T02:13:42.000Z","size":101,"stargazers_count":17,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-04T19:49:35.798Z","etag":null,"topics":["async-await","async-javascript","ebook","gitbook","gitchat","javascript","promise","tutorial"],"latest_commit_sha":null,"homepage":"https://meathill.gitbooks.io/javascript-async-tutorial/content/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/meathill.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-16T02:53:38.000Z","updated_at":"2023-04-11T15:36:14.000Z","dependencies_parsed_at":"2022-09-03T23:01:43.470Z","dependency_job_id":null,"html_url":"https://github.com/meathill/gitbook-javascript-async-tutorial","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/meathill/gitbook-javascript-async-tutorial","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meathill%2Fgitbook-javascript-async-tutorial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meathill%2Fgitbook-javascript-async-tutorial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meathill%2Fgitbook-javascript-async-tutorial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meathill%2Fgitbook-javascript-async-tutorial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/meathill","download_url":"https://codeload.github.com/meathill/gitbook-javascript-async-tutorial/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meathill%2Fgitbook-javascript-async-tutorial/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265431653,"owners_count":23764031,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async-await","async-javascript","ebook","gitbook","gitchat","javascript","promise","tutorial"],"created_at":"2024-11-23T11:25:13.056Z","updated_at":"2025-07-15T11:31:39.742Z","avatar_url":"https://github.com/meathill.png","language":"JavaScript","readme":"前言\n========\n\n为解决异步函数的回调陷阱，开发社区不断摸索，终于折腾出 Promise/A+。它的优势非常显著：\n\n1. 不增加新的语法，可以立刻适配几乎所有浏览器\n2. 以队列的形式组织代码，易读好改\n3. 捕获异常方案也基本可用\n\n这套方案在迭代中逐步完善，最终被吸收进 ES2015。不仅如此，ES2017 中还增加了 Await/Async，可以用顺序的方式书写异步代码，甚至可以正常抛出捕获错误，维护同一个栈。可以说彻底解决了异步回调的问题。\n\n现在大部分浏览器和 Node.js 都已原生支持 Promise，很多类库也开始返回 Promise 对象，更有各种降级适配策略。Node.js 7+ 则实装了 Await/Async。如果您现在还不会使用，那么我建议您尽快学习一下。本文我准备结合近期的开发经验，全面介绍现代化的 JavaScript 异步开发。\n\n## 关于这本书\n\n这本书最开始的内容源于我在 [SegmentFault](https://segmentfault.com/) 做的一场分享： [Promise 的 N 种用法](https://segmentfault.com/l/1500000008757392)。\n\n后来去 GitChat 分享时，选题比较犯难，就跟运营妹子商量要不再做一次同样题目，这样我也省事儿。结果挂出来后乏人问津，只好再跟运营开会讨论，然后决定更名为[《JavaScript 异步开发攻略》](http://gitbook.cn/books/594541981b8e4b4036720fc9/index.html)，并且增加非 Promise 的内容。改名后终于过了下限，然后我就动手写，于是便有了这本小书。\n\n我写这本书时就打算根据环境发展随时更新内容，没想到 GitChat 设计成后期不允许修改文章，要改只能把内容发给运营人工修改。因为我写的时候为了分章节好维护好管理，用的是 Git + Gitbook，索性脆放到 Gitbook 上好了。名字也改成现在这个样子，增加一个“全”字。\n\n## 目标读者要求\n\n1. 前端水平：初级、中级\n2. 了解 JavaScript\n3. 最好有异步开发经历，希望写出更好的代码\n\n## 名词及约定\n\n* ES6 = ES2015\n* ES7 = ES2016 + ES2017\n* 异步函数 = Async Functions = Await/Async\n\n范例代码会使用 ES6 的语法，也会混用 ES6 Module 和 CommonJS，请大家不要见怪。我会在代码当中加注释，其中会有一些关键内容，请大家不要忽略。\n\n本文中所有代码均以 Node.js 7.0 为基础。\n\n## 作者介绍\n\n大家好，我叫翟路佳，花名“肉山”，这个名字跟 Dota 没关系，从高中起伴随我到现在。\n\n我热爱编程，喜欢学习，喜欢分享，从业十余年，投入的比较多，学习积累到的也比较多，对前端方方面面都有所了解，希望能与大家分享。\n\n我兴趣爱好比较广泛，尤其喜欢旅游，欢迎大家相互交流。\n\n你可以在这里找到我：\n\n* [博客](http://blog.meathill.com)\n* [微博](http://weibo.com/meathill)\n* [GitHub](https://github.com/meathill)\n\n## 版权许可\n\n本书采用[“保持署名—非商用”创意共享4.0许可证](https://creativecommons.org/licenses/by-nc/4.0/)。\n\n只要保持原作者署名和非商用，您可以自由地阅读、分享、修改本书。\n\n## 反馈\n\n如果您对于文中的内容有任何疑问，请在评论或 [Issue](https://github.com/meathill/javascript-async-tutorial/issues) 中告诉我。亦可发邮件给我：meathill[at]gmail.com。谢谢。","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeathill%2Fgitbook-javascript-async-tutorial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmeathill%2Fgitbook-javascript-async-tutorial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeathill%2Fgitbook-javascript-async-tutorial/lists"}