aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/javascript/reference/errors/read-only
diff options
context:
space:
mode:
Diffstat (limited to 'files/ja/web/javascript/reference/errors/read-only')
-rw-r--r--files/ja/web/javascript/reference/errors/read-only/index.html85
-rw-r--r--files/ja/web/javascript/reference/errors/read-only/index.md86
2 files changed, 86 insertions, 85 deletions
diff --git a/files/ja/web/javascript/reference/errors/read-only/index.html b/files/ja/web/javascript/reference/errors/read-only/index.html
deleted file mode 100644
index f3c6566eac..0000000000
--- a/files/ja/web/javascript/reference/errors/read-only/index.html
+++ /dev/null
@@ -1,85 +0,0 @@
----
-title: 'TypeError: "x" is read-only'
-slug: Web/JavaScript/Reference/Errors/Read-only
-tags:
- - Error
- - Errors
- - JavaScript
- - TypeError
-translation_of: Web/JavaScript/Reference/Errors/Read-only
----
-<div>{{jsSidebar("Errors")}}</div>
-
-<p>The JavaScript <a href="/en-US/docs/Web/JavaScript/Reference/Strict_mode">strict
- mode</a>-only exception "is read-only" occurs when a global variable or object
- property that was assigned to is a read-only property.</p>
-
-<h2 id="Message">エラーメッセージ</h2>
-
-<pre class="brush: js">TypeError: Assignment to read-only properties is not allowed in strict mode (Edge)
-TypeError: "x" is read-only (Firefox)
-TypeError: 0 is read-only (Firefox)
-TypeError: Cannot assign to read only property 'x' of #&lt;Object&gt; (Chrome)
-TypeError: Cannot assign to read only property '0' of [object Array] (Chrome)
-</pre>
-
-<h2 id="Error_type">エラーの種類</h2>
-
-<p>{{jsxref("TypeError")}}</p>
-
-<h2 id="何がうまくいかなかったのか?">何がうまくいかなかったのか?</h2>
-
-<p>値を割り当てようとしたグローバル変数、またはオブジェクトのプロパティが読み取り専用プロパティです。 (技術的には、 <a href="/ja/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty#writable_attribute">non-writable データプロパティ</a> です。)</p>
-
-<p>このエラーは、<a href="/ja/docs/Web/JavaScript/Reference/Strict_mode">strict モードコード</a> のときにだけ発生します。strict コードではない場合、割り当ては無視されるだけです。</p>
-
-<h2 id="例">例</h2>
-
-<h3 id="無効なケース">無効なケース</h3>
-
-<p>読み取り専用プロパティはさほど一般的ではありませんが、 {{jsxref("Object.defineProperty()")}}、または {{jsxref("Object.freeze()")}} を使用して生成できます。</p>
-
-<pre class="brush: js example-bad">'use strict';
-var obj = Object.freeze({name: 'Elsa', score: 157});
-obj.score = 0; // TypeError
-
-'use strict';
-Object.defineProperty(this, 'LUNG_COUNT', {value: 2, writable: false});
-LUNG_COUNT = 3; // TypeError
-
-'use strict';
-var frozenArray = Object.freeze([0, 1, 2]);
-frozenArray[0]++; // TypeError
-</pre>
-
-<p>JavaScript の組み込みにも、いくつか読み取り専用プロパティがあります。 Math の定数を再定義しようとしたとします。</p>
-
-<pre class="brush: js example-bad">'use strict';
-Math.PI = 4; // TypeError
-</pre>
-
-<p>残念ながらできません。</p>
-
-<p>グローバル変数の <code>undefined</code> も読み取り専用のため、このようにすると悪名高い "undefined is not a function" エラーが発生します。</p>
-
-<pre class="brush: js example-bad">'use strict';
-undefined = function() {}; // TypeError: "undefined" is read-only
-</pre>
-
-<h3 id="Valid_cases">有効な場合</h3>
-
-<pre class="brush: js example-good">'use strict';
-var obj = Object.freeze({name: 'Score', points: 157});
-obj = {name: obj.name, points: 0}; // 新しいオブジェクトで置き換える
-
-'use strict';
-var LUNG_COUNT = 2; // `var` が使われているので、読み取り専用ではない
-LUNG_COUNT = 3; // ok (解剖学的にはおかしいけれども)
-</pre>
-
-<h2 id="関連項目">関連項目</h2>
-
-<ul>
- <li>{{jsxref("Object.defineProperty()")}}</li>
- <li>{{jsxref("Object.freeze()")}}</li>
-</ul>
diff --git a/files/ja/web/javascript/reference/errors/read-only/index.md b/files/ja/web/javascript/reference/errors/read-only/index.md
new file mode 100644
index 0000000000..4e6ea7f36b
--- /dev/null
+++ b/files/ja/web/javascript/reference/errors/read-only/index.md
@@ -0,0 +1,86 @@
+---
+title: 'TypeError: "x" is read-only'
+slug: Web/JavaScript/Reference/Errors/Read-only
+tags:
+ - Error
+ - Errors
+ - JavaScript
+ - TypeError
+translation_of: Web/JavaScript/Reference/Errors/Read-only
+---
+{{jsSidebar("Errors")}}
+
+JavaScript の [strict モード](/ja/docs/Web/JavaScript/Reference/Strict_mode)のみの例外 "is read-only" は、代入されたグローバル変数またはオブジェクトプロパティが読み取り専用プロパティであった場合に発生します。
+
+## エラーメッセージ
+
+```js
+TypeError: Assignment to read-only properties is not allowed in strict mode (Edge)
+TypeError: "x" is read-only (Firefox)
+TypeError: 0 is read-only (Firefox)
+TypeError: Cannot assign to read only property 'x' of #<Object> (Chrome)
+TypeError: Cannot assign to read only property '0' of [object Array] (Chrome)
+```
+
+## エラーの種類
+
+{{jsxref("TypeError")}}
+
+## エラーの原因
+
+代入しようとしたグローバル変数、またはオブジェクトのプロパティが読み取り専用プロパティです。 (技術的には、 [non-writable データプロパティ](/ja/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty#Writable_attribute)です。)
+
+このエラーは、 [strict モードのコード](/en-US/docs/Web/JavaScript/Reference/Strict_mode)にだけ発生します。 strict コードではない場合、割り当ては無視されるだけです。</p>
+
+## 例
+
+### 無効な場合
+
+<p>読み取り専用プロパティはさほど一般的ではありませんが、 {{jsxref("Object.defineProperty()")}}、または {{jsxref("Object.freeze()")}} を使用して生成することができます。</p>
+
+```js example-bad
+'use strict';
+var obj = Object.freeze({name: 'Elsa', score: 157});
+obj.score = 0; // TypeError
+
+'use strict';
+Object.defineProperty(this, 'LUNG_COUNT', {value: 2, writable: false});
+LUNG_COUNT = 3; // TypeError
+
+'use strict';
+var frozenArray = Object.freeze([0, 1, 2]);
+frozenArray[0]++; // TypeError
+```
+
+JavaScript の組み込みにも、いくつか読み取り専用プロパティがあります。数学的な定数を再定義しようとしたとします。
+
+```js example-bad
+'use strict';
+Math.PI = 4; // TypeError
+```
+
+残念ながらできません。
+
+グローバル変数の `undefined` も読み取り専用のため、このようにすると悪名高い "undefined is not a function" エラーが発生します。
+
+```js example-bad
+'use strict';
+undefined = function() {}; // TypeError: "undefined" is read-only
+```
+
+### 有効な場合
+
+```js example-good
+'use strict';
+var obj = Object.freeze({name: 'Score', points: 157});
+obj = {name: obj.name, points: 0}; // 新しいオブジェクトで置き換える
+
+'use strict';
+var LUNG_COUNT = 2; // `var` が使われているので、読み取り専用ではない
+LUNG_COUNT = 3; // ok (解剖学的にはおかしいけれども)
+```
+
+## 関連情報
+
+- {{jsxref("Object.defineProperty()")}}
+- {{jsxref("Object.freeze()")}}