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

<p><strong><code>setBigInt64()</code></strong>方法在距{{jsxref("DataView")}} 的起始位置的指定字节偏移处存储一个带符号的64位整数(long long类型)值。</p>

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



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

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

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

<dl>
 <dt>byteOffset</dt>
 <dd>字节偏移量,为从视图的起始位置到数据存储位置的字节字节偏移量。</dd>
 <dt></dt>
 <dt>value</dt>
 <dd>作为一个{{jsxref("BigInt")}}类型设置的数值。满足一个带符号的64位整数的最大可能数值是 <code>2n ** (64n -1n) - 1n</code> (<code>9223372036854775807n</code>)。当发生溢出时,将会变成负数(<code>-9223372036854775808n</code>)。</dd>
 <dt>littleEndian</dt>
 <dd>{{optional_inline}} 为可选参数,表示这个64位整数是否以{{Glossary("Endianness", "little-endian 或者big-endian")}}格式存储。如果设置为<code>false</code> 或者未指定(<code>undefined</code>),将会写入一个big-endian(大端模式:高位字节排放在内存的低地址端,低位字节排放在内存的高地址端)格式的数值。</dd>
</dl>

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

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

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

<dl>
 <dt>{{jsxref("RangeError")}}</dt>
 <dd>如果 <code>byteOffset</code>设置导致存储该数值时超出了视图的末尾位置,将会抛出错误。</dd>
</dl>

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

<h3 id="使用_setBigInt64_方法">使用 <code>setBigInt64</code> 方法</h3>

<pre class="brush:js">var buffer = new ArrayBuffer(8);
var dataview = new DataView(buffer);
dataview.setBigInt64(0, 3n);
dataview.getBigInt64(0); // 3n
</pre>

<h2 id="相关规范">相关规范</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">规范</th>
   <th scope="col">状态</th>
   <th scope="col">解释</th>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-dataview.prototype.setbigint64', 'DataView.prototype.setBigInt64()')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td>    </td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</h2>



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

<h2 id="请参阅">请参阅</h2>

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