aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMasahiro FUJIMOTO <mfujimot@gmail.com>2021-04-09 23:01:21 +0900
committerpotappo <potappo@gmail.com>2021-04-12 21:15:14 +0900
commite67828880f24835a91326903f6be4a8c336c20f7 (patch)
tree106367439a79cb77bfa09714572558877d6a154b
parent514bde5f87ba3496decd17deab1a70f43b68f405 (diff)
downloadtranslated-content-e67828880f24835a91326903f6be4a8c336c20f7.tar.gz
translated-content-e67828880f24835a91326903f6be4a8c336c20f7.tar.bz2
translated-content-e67828880f24835a91326903f6be4a8c336c20f7.zip
Web/JavaScript/Reference/Operators/async_function を更新
2021/03/26 時点の英語版に同期
-rw-r--r--files/ja/web/javascript/reference/operators/async_function/index.html105
1 files changed, 53 insertions, 52 deletions
diff --git a/files/ja/web/javascript/reference/operators/async_function/index.html b/files/ja/web/javascript/reference/operators/async_function/index.html
index b2e2b5476e..f50d024a21 100644
--- a/files/ja/web/javascript/reference/operators/async_function/index.html
+++ b/files/ja/web/javascript/reference/operators/async_function/index.html
@@ -2,41 +2,46 @@
title: 非同期関数式
slug: Web/JavaScript/Reference/Operators/async_function
tags:
- - Experimental
- - Function
- - JavaScript
- - Operator
- - Primary Expression
+- Function
+- JavaScript
+- Language feature
+- Operator
+- Primary Expression
translation_of: Web/JavaScript/Reference/Operators/async_function
---
<div>{{jsSidebar("Operators")}}</div>
-<p><strong><code>async function</code></strong> キーワードは、式内で async function を定義するために使用できます。</p>
+<p><strong><code>async function</code></strong> キーワードは、式の中で <code>async</code> 関数を定義するために使用できます。</p>
-<h2 id="構文">構文</h2>
+<p>非同期関数は、 <a
+ href="/ja/docs/Web/JavaScript/Reference/Statements/async_function">async function 文</a>を使用して定義することもできます。</p>
-<pre class="syntaxbox">async function [<em>name</em>]([<em>param1</em>[, <em>param2[</em>, ..., <em>paramN</em>]]]) {
- <em>statements</em>
+<h2 id="Syntax">構文</h2>
+
+<pre class="brush: js">async function [<var>name</var>]([<var>param1</var>[, <var>param2</var>[, ..., <var>paramN</var>]]]) {
+ <var>statements</var>
}</pre>
-<h3 id="引数">引数</h3>
+<p>ES2015 では、<a href="/ja/docs/Web/JavaScript/Reference/Functions/Arrow_functions">アロー関数</a>を使用することもできます。</p>
+
+<h3 id="Parameters">引数</h3>
<dl>
- <dt><code>name</code></dt>
- <dd>関数名。関数が<em>匿名</em>の場合、省略可能。名前は関数ボディー内のみのローカル。</dd>
- <dt><code>paramN</code></dt>
- <dd>関数に渡される引数名。</dd>
- <dt><code>statements</code></dt>
- <dd>関数ボディーを構成するステートメント。</dd>
+ <dt><code>name</code></dt>
+ <dd>関数名です。関数が<em>無名</em>の場合は省略可能です。名前は関数の本体内のみのローカルです。</dd>
+ <dt><code>paramN</code></dt>
+ <dd>関数に渡される引数名です。</dd>
+ <dt><code>statements</code></dt>
+ <dd>関数本体を構成する文です。</dd>
</dl>
-<h2 id="説明">説明</h2>
+<h2 id="Description">解説</h2>
-<p><code>async function</code> 式は {{jsxref('Statements/async_function', 'async function statement')}} と非常に似ており、構文もほとんど同じです。async <code>function</code> 式と async <code>function</code> ステートメントの主な違いは、<code>async function</code> 式は<em>匿名</em>関数を生成するために<em>関数名</em>を省略できる点です。<code>async function</code> 式は、定義後直ちに実行される <strong>IIFE</strong>(即時実行関数式)として使用することもできます。詳細は <a href="/ja/docs/Web/JavaScript/Reference/Functions">function</a> の章を見てください。</p>
+<p><code>async function</code> 式は {{jsxref('Statements/async_function', 'async function statement')}} と非常に似ており、構文もほとんど同じです。async <code>function</code> 式と async <code>function</code> 文の主な違いは、<code>async function</code> 式が<em>無名</em>関数を生成するために<em>関数名</em>を省略できる点です。<code>async function</code> 式は、定義後直ちに実行される <strong>IIFE</strong> (即時実行関数式) として使用することもできます。詳細は<a href="/ja/docs/Web/JavaScript/Reference/Functions">関数</a>の章を見てください。</p>
-<h2 id="例">例</h2>
+<h2 id="Examples">例</h2>
-<h3 id="シンプルな例">シンプルな例</h3>
+<h3 id="Simple_example">シンプルな例</h3>
<pre class="brush: js">function resolveAfter2Seconds(x) {
return new Promise(resolve =&gt; {
@@ -46,52 +51,48 @@ translation_of: Web/JavaScript/Reference/Operators/async_function
});
};
-(async function(x) { // async function expression used as an IIFE
- var a = resolveAfter2Seconds(20);
- var b = resolveAfter2Seconds(30);
- return x + await a + await b;
-})(10).then(v =&gt; {
- console.log(v); // prints 60 after 2 seconds.
-});
-
-var add = async function(x) { // async function expression assigned to a variable
- var a = await resolveAfter2Seconds(20);
- var b = await resolveAfter2Seconds(30);
+const add = async function(x) { // 変数に代入された非同期関数式
+ let a = await resolveAfter2Seconds(20);
+ let b = await resolveAfter2Seconds(30);
return x + a + b;
};
add(10).then(v =&gt; {
- console.log(v); // prints 60 after 4 seconds.
+ console.log(v); // 4 秒後に 60 を表示
+});
+
+(async function(x) { // IIFE として使用される非同期関数式
+ let p_a = resolveAfter2Seconds(20);
+ let p_b = resolveAfter2Seconds(30);
+ return x + await p_a + await p_b;
+})(10).then(v =&gt; {
+ console.log(v); // 2 秒後に 60 を表示
});
</pre>
-<h2 id="仕様">仕様</h2>
+<h2 id="Specifications">仕様書</h2>
<table class="standard-table">
- <thead>
- <tr>
- <th scope="col">仕様</th>
- <th scope="col">ステータス</th>
- <th scope="col">コメント</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>{{SpecName('Async Function', '#async-function-definitions', 'async function')}}</td>
- <td>{{Spec2('Async Function')}}</td>
- <td>提案</td>
- </tr>
- </tbody>
+ <thead>
+ <tr>
+ <th scope="col">仕様書</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-async-function-definitions', 'async function')}}</td>
+ </tr>
+ </tbody>
</table>
-<h2 id="ブラウザー実装状況">ブラウザー実装状況</h2>
+<h2 id="Browser_compatibility">ブラウザーの互換性</h2>
<p>{{Compat("javascript.operators.async_function")}}</p>
-<h2 id="関連項目">関連項目</h2>
+<h2 id="See_also">関連情報</h2>
<ul>
- <li>{{jsxref("Statements/async_function", "async function")}}</li>
- <li>{{jsxref("AsyncFunction")}} オブジェクト</li>
- <li>{{jsxref("Operators/await", "await")}}</li>
+ <li>{{jsxref("Statements/async_function", "async function")}}</li>
+ <li>{{jsxref("AsyncFunction")}} オブジェクト</li>
+ <li>{{jsxref("Operators/await", "await")}}</li>
</ul>