blob: c742ebaf2ed99da0d3e00da1210acdceffdaa6bb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
---
title: 'Warning: expression closures are deprecated'
slug: Web/JavaScript/Reference/Errors/Deprecated_expression_closures
tags:
- JavaScript
- Warning
- エラー
- 警告
translation_of: Web/JavaScript/Reference/Errors/Deprecated_expression_closures
---
<div>{{jsSidebar("Errors")}}</div>
<p>JavaScript の警告 "expression closures are deprecated" は、標準外の<a href="/ja/docs/Web/JavaScript/Reference/Operators/Expression_closures">式クロージャ</a>構文 (略記関数構文) が使用されたときに発生します。</p>
<h2 id="Message" name="Message">メッセージ</h2>
<pre class="syntaxbox">Warning: expression closures are deprecated
</pre>
<h2 id="Error_type">エラーの種類</h2>
<p>警告。 JavaScript の実行は中断されません。</p>
<h2 id="What_went_wrong" name="What_went_wrong">原因</h2>
<p>標準外の<a href="/ja/docs/Web/JavaScript/Reference/Operators/Expression_closures">式クロージャ</a>構文 (略記関数構文) は非推奨のため、使用すべきではありません。この構文は <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1083458">bug 1083458</a> で削除予定であり、削除された後は {{jsxref("SyntaxError")}} が発生します。</p>
<h2 id="Examples" name="Examples">例</h2>
<h3 id="Deprecated_syntax" name="Deprecated_syntax">非推奨の構文</h3>
<p>式クロージャで、中括弧を省略したり、関数宣言やメソッド定義で return 文を省略したりすることです。</p>
<pre class="brush: js example-bad">var x = function() 1;
var obj = {
count: function() 1
};
</pre>
<h3 id="Standard_syntax" name="Standard_syntax">標準の構文</h3>
<p>標準外の式クロージャ構文から標準の ECMAScript 構文に変換するためには、波括弧と return ステートメントを追加します。</p>
<pre class="brush: js example-good">var x = function() { return 1; }
var obj = {
count: function() { return 1; }
};
</pre>
<h3 id="Standard_syntax_using_arrow_functions" name="Standard_syntax_using_arrow_functions">アロー関数を使用した標準の構文</h3>
<p>代わりに<a href="/ja/docs/Web/JavaScript/Reference/Functions/Arrow_functions">アロー関数</a>を使用することもできます。</p>
<pre class="brush: js example-good">var x = () => 1;</pre>
<h3 id="Standard_syntax_using_shorthand_method_syntax" name="Standard_syntax_using_shorthand_method_syntax">略記メソッド構文を使用した標準構文</h3>
<p>次のように、式クロージャがゲッターとセッターにも見られることがあります。</p>
<pre class="brush: js example-bad">var obj = {
get x() 1,
set x(v) this.v = v
};
</pre>
<p>ES2015 の<a href="/ja/docs/Web/JavaScript/Reference/Functions/Method_definitions">メソッド定義</a>で、次のように変換することができます。</p>
<pre class="brush: js example-good">var obj = {
get x() { return 1 },
set x(v) { this.v = v }
};
</pre>
<h2 id="See_also" name="See_also">関連情報</h2>
<ul>
<li><a href="/ja/docs/Web/JavaScript/Reference/Operators/Expression_closures">式クロージャ</a></li>
<li><a href="/ja/docs/Web/JavaScript/Reference/Functions/Arrow_functions">アロー関数</a></li>
<li><a href="/ja/docs/Web/JavaScript/Reference/Functions/Method_definitions">メソッド定義</a></li>
</ul>
|