blob: 2b545d9c0372b85e52a71628ba12bc8c9912c338 (
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
83
84
85
86
87
|
---
title: ArrayBuffer.isView()
slug: Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView
tags:
- 类型数组
- 缓冲区
translation_of: Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView
---
<div>{{JSRef}}</div>
<p><code><strong>ArrayBuffer.isView()</strong></code> 方法用来判断传入的参数值是否是一种 <code>ArrayBuffer</code> 视图(view),比如类型化数组对象(<a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray">typed array objects</a>)或者数据视图( {{jsxref("DataView")}})。</p>
<div>{{EmbedInteractiveExample("pages/js/arraybuffer-isview.html")}}</div>
<h2 id="语法">语法</h2>
<pre class="brush: js"><code>ArrayBuffer.isView(<var>value</var>)</code></pre>
<h3 id="参数">参数</h3>
<dl>
<dt><code>value</code></dt>
<dd>被检测的值。</dd>
</dl>
<h3 id="返回值">返回值</h3>
<dl>
<dt><code>true</code></dt>
<dd>如果提供的参数是一种 {{jsxref("ArrayBuffer")}} 视图;</dd>
<dt><code>false</code></dt>
<dd>提供的参数不是一种 {{jsxref("ArrayBuffer")}} 视图类型;</dd>
</dl>
<h2 id="示例">示例</h2>
<pre class="brush: js">ArrayBuffer.isView(); // false
ArrayBuffer.isView([]); // false
ArrayBuffer.isView({}); // false
ArrayBuffer.isView(null); // false
ArrayBuffer.isView(undefined); // false
ArrayBuffer.isView(new ArrayBuffer(10)); // false
ArrayBuffer.isView(new Uint8Array()); // true
ArrayBuffer.isView(new Float32Array()); // true
ArrayBuffer.isView(new Int8Array(10).subarray(0, 3)); // true
var buffer = new ArrayBuffer(2);
var dv = new DataView(buffer);
ArrayBuffer.isView(dv); // true
</pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
<tr>
<td>{{SpecName('Typed Array')}}</td>
<td>{{Spec2('Typed Array')}}</td>
<td>Superseded by ECMAScript 6.</td>
</tr>
<tr>
<td>{{SpecName('ES6', '#sec-arraybuffer.isview', 'ArrayBuffer.isView')}}</td>
<td>{{Spec2('ES6')}}</td>
<td>Initial definition in an ECMA standard.</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<p>{{Compat("javascript.builtins.ArrayBuffer.isView")}}</p>
<h2 id="另见">另见</h2>
<ul>
<li><a href="/en-US/docs/Web/JavaScript/Typed_arrays" title="en/JavaScript typed arrays">JavaScript typed arrays</a></li>
</ul>
|