aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/dataview/setint16/index.html
blob: 92d8deb9754b72983b32ebd0173c348f2f5ca316 (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
---
title: DataView.prototype.setInt16()
slug: Web/JavaScript/Reference/Global_Objects/DataView/setInt16
translation_of: Web/JavaScript/Reference/Global_Objects/DataView/setInt16
---
<div>{{JSRef}}</div>

<p><strong><code>setInt16()</code></strong><code></code><a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/DataView" title="DataView 视图提供了一种用于向 ArrayBuffer 读写数据的底层接口。"><code>DataView</code></a>起始位置以byte为计数的指定偏移量(byteOffset)处储存一个16-bit数(短整型).</p>

<div>{{EmbedInteractiveExample("pages/js/dataview-setint16.html")}}</div>



<h2 id="语法">语法</h2>

<pre class="syntaxbox"><var>dataview</var>.setInt16(byteOffset, value [, littleEndian])</pre>

<h3 id="参数">参数</h3>

<dl>
 <dt>byteOffset</dt>
 <dd>偏移量,从头开始计算,单位为字节.</dd>
 <dt>value</dt>
 <dd>设置的数值.</dd>
 <dt>littleEndian</dt>
 <dd>{{optional_inline}} Indicates whether the 16-bit int is stored in {{Glossary("Endianness", "little- or big-endian")}} format. If false or undefined, a big-endian value is written.</dd>
</dl>

<h3 id="返回">返回</h3>

<p>{{jsxref("undefined")}}.</p>

<h3 id="抛出错误">抛出错误</h3>

<dl>
 <dt>{{jsxref("RangeError")}}</dt>
 <dd>如果byteOffset超出了视图能储存的值,就会抛出错误.</dd>
</dl>

<h2 id="例子">例子</h2>

<pre class="brush:js">var buffer = new ArrayBuffer(8);
var dataview = new DataView(buffer);
dataview.setInt16(1, 3);
dataview.getInt16(1); // 3
</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-dataview.prototype.setint16', 'DataView.prototype.setInt16')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td>Initial definition in an ECMA standard.</td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-dataview.prototype.setint16', 'DataView.prototype.setInt16')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器支持">浏览器支持</h2>



<p>{{Compat("javascript.builtins.DataView.setInt16")}}</p>

<h2 id="相关内容">相关内容</h2>

<ul>
 <li>{{jsxref("DataView")}}</li>
 <li>{{jsxref("ArrayBuffer")}}</li>
</ul>