| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Operators/async_function | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. Its been available across browsers since 2017 ..
async function .
async function [name]([param1[, param2[, ..., paramN]]]) {
statements
}
ES2015, .
name. , . .
paramN, .
statements, .
async function , , async function statement. async function async function , async function . async function IIFE (Immediately Invoked Function Expression), . .
function resolveAfter2Seconds(x) {
return new Promise((resolve) => {
setTimeout(() => {
resolve(x);
}, 2000);
});
}
(async function (x) {
// IIFE
var a = resolveAfter2Seconds(20);
var b = resolveAfter2Seconds(30);
return x + (await a) + (await b);
})(10).then((v) => {
console.log(v); // 60 2 .
});
var add = async function (x) {
//
var a = await resolveAfter2Seconds(20);
var b = await resolveAfter2Seconds(30);
return x + a + b;
};
add(10).then((v) => {
console.log(v); // 60 4 .
});
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-async-function-definitions |
async functionAsyncFunction objectawaitThis page was last modified on 17 . 2024 . by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |