diff options
Diffstat (limited to 'files/zh-cn/web/javascript')
-rw-r--r-- | files/zh-cn/web/javascript/reference/errors/typed_array_invalid_arguments/index.html | 76 |
1 files changed, 0 insertions, 76 deletions
diff --git a/files/zh-cn/web/javascript/reference/errors/typed_array_invalid_arguments/index.html b/files/zh-cn/web/javascript/reference/errors/typed_array_invalid_arguments/index.html deleted file mode 100644 index 314a4a425c..0000000000 --- a/files/zh-cn/web/javascript/reference/errors/typed_array_invalid_arguments/index.html +++ /dev/null @@ -1,76 +0,0 @@ ---- -title: 'TypeError: invalid arguments' -slug: Web/JavaScript/Reference/Errors/Typed_array_invalid_arguments -tags: - - JavaScript - - 类型错误 - - 错误提示 -translation_of: Web/JavaScript/Reference/Errors/Typed_array_invalid_arguments ---- -<div>{{jsSidebar("Errors")}}</div> - -<h2 id="错误提示">错误提示</h2> - -<pre class="syntaxbox">TypeError: invalid arguments (Firefox)</pre> - -<h2 id="错误类型">错误类型</h2> - -<p>{{jsxref("TypeError")}}</p> - -<h2 id="哪里出错了?">哪里出错了?</h2> - -<p><a href="/en-US/docs/Web/JavaScript/Typed_arrays">类型化数组(Typed array</a>) 的构造器可以通过接收以下类型的参数中的一种</p> - -<ul> - <li>表示长度的数字,</li> - <li>另外一个类型化数组,</li> - <li>类数组对象,</li> - <li>可迭代对象,</li> - <li>一个 {{jsxref("ArrayBuffer")}} 对象</li> -</ul> - -<p>来创建一个新的类型化数组。其他类型的构造器参数都无法创建合法的类型化数组。</p> - -<h2 id="示例">示例</h2> - -<p>类型化数组——例如 {{jsxref("Uint8Array")}} ——无法通过字符串创建。实际上,字符串根本不能出现在类型化数组中。</p> - -<pre class="brush: js example-bad">var ta = new Uint8Array("nope"); -// TypeError: invalid arguments -</pre> - -<p>创建一个合法的 {{jsxref("Uint8Array")}} 对象的不同方式:</p> - -<pre class="brush: js example-good">// From a length -var uint8 = new Uint8Array(2); -uint8[0] = 42; -console.log(uint8[0]); // 42 -console.log(uint8.length); // 2 -console.log(uint8.BYTES_PER_ELEMENT); // 1 - -// From an array -var arr = new Uint8Array([21,31]); -console.log(arr[1]); // 31 - -// From another TypedArray -var x = new Uint8Array([21, 31]); -var y = new Uint8Array(x); -console.log(y[0]); // 21 - -// From an ArrayBuffer -var buffer = new ArrayBuffer(8); -var z = new Uint8Array(buffer, 1, 4); - -// From an iterable -var iterable = function*(){ yield* [1,2,3]; }(); -var uint8 = new Uint8Array(iterable); -// Uint8Array[1, 2, 3] -</pre> - -<h2 id="相关内容">相关内容</h2> - -<ul> - <li><a href="/en-US/docs/Web/JavaScript/Typed_arrays">Typed arrays</a></li> - <li>{{jsxref("ArrayBuffer")}}</li> - <li>{{jsxref("Uint8Array")}}</li> -</ul> |