Javascript 现在使用 async/await 安全吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42183155/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it safe to use async/await now?
提问by Abhijeet
Is it safe to use async-await in Javascript instead of generators-promises now, knowing that the syntax has not made yet and will be coming with the release of ES8?
现在在 Javascript 中使用 async-await 而不是 generators-promises 是否安全,因为语法尚未制定并且将随着 ES8 的发布而出现?
What browsers can I count on it being available, and how common are the browsers where this syntax is not available? By Safe I mean without some transpilers like babel?
我可以指望哪些浏览器可用,以及这种语法不可用的浏览器有多常见?安全是指没有像 babel 这样的转译器?
回答by slebetman
There are two places I check whenever I have questions such as this:
每当我有这样的问题时,我都会检查两个地方:
The Can I Usewebsite: http://caniuse.com/#search=await
在我可以使用网站:http://caniuse.com/#search=await
And Node Green: http://node.green/#async-functions
和节点绿色:http: //node.green/#async-functions
Typically an answer is encouraged to include the relevant information to avoid link rot. But ironically this answer has exactly the opposite problem: this answer will rot (the information below will become invalid) long before the links above. So always check caniuse and node.green first:
通常鼓励答案包含相关信息以避免链接失效。但具有讽刺意味的是,这个答案有完全相反的问题:这个答案会在上面的链接之前很久就腐烂(下面的信息将变得无效)。所以总是先检查 caniuse 和 node.green:
From caniuse.com as of April 2019 :
来自 caniuse.com 截至 2019 年 4 月:
- IE*: NOT SUPPORTED (most used version = 11)
- Edge: From version 15 (most used version = 17)
- Firefox: From version 52 (most used version = 65)
- Chrome: From version 55 (most used version = 72)
- Safari: From version 10.1 (most used version = 12)
- Opera: From version 42 (most used version = 58)
- iOS Safari: From version 10.3 (most used version = 12.1)
- Opera Mini*: NOT SUPPORTED
- Android Browser*: From 5 (most used version = 4.4)
- Chrome for Android: From version 55 (most used version = 71)
- IE*:不支持(最常用的版本 = 11)
- Edge:从版本 15(最常用的版本 = 17)
- Firefox:从版本 52(最常用的版本 = 65)
- Chrome:从版本 55(最常用的版本 = 72)
- Safari:从 10.1 版开始(最常用的版本 = 12)
- Opera:从版本 42(最常用的版本 = 58)
- iOS Safari:从 10.3 版开始(最常用的版本 = 12.1)
- Opera Mini*:不支持
- Android 浏览器*:从 5(最常用的版本 = 4.4)
- Android版Chrome:从 55 版开始(最常用的版本 = 71)
From node.green as of April 2019
来自 node.green 截至 2019 年 4 月
- Node.js: From version 8.0.0
- Node.js:从 8.0.0 版本开始
So depending on what you think is acceptable it is either safe or not safe. Note the following:
因此,取决于您认为可以接受的内容,它是安全的还是不安全的。请注意以下事项:
- This question was originally asked on 2017, and we have come a long way so async/await is much more safe to use now.
- By 2019, most mobile devices already support async/await.
- Node 8 is released on May 2017 so it should be safe to use async/await on Node.js unless your Node.js servers are very outdated.
- 这个问题最初是在 2017 年提出的,我们已经走了很长一段路,所以现在使用 async/await 更加安全。
- 到 2019 年,大多数移动设备已经支持 async/await。
- Node 8 于 2017 年 5 月发布,因此除非您的 Node.js 服务器非常过时,否则在 Node.js 上使用 async/await 应该是安全的。

