diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/javascript/reference/global_objects/dataview/setint8 | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/dataview/setint8')
-rw-r--r-- | files/zh-cn/web/javascript/reference/global_objects/dataview/setint8/index.html | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/dataview/setint8/index.html b/files/zh-cn/web/javascript/reference/global_objects/dataview/setint8/index.html new file mode 100644 index 0000000000..dc7c7b30e4 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/dataview/setint8/index.html @@ -0,0 +1,80 @@ +--- +title: DataView.prototype.setInt8() +slug: Web/JavaScript/Reference/Global_Objects/DataView/setInt8 +translation_of: Web/JavaScript/Reference/Global_Objects/DataView/setInt8 +--- +<div>{{JSRef}}</div> + +<p><strong><code>setInt8()</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)处储存一个8-bit数(一个字节).</p> + +<div>{{EmbedInteractiveExample("pages/js/dataview-setint8.html")}}</div> + + + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox"><var>dataview</var>.setInt8(byteOffset, value)</pre> + +<h2 id="参数">参数</h2> + +<dl> + <dt>byteOffset</dt> + <dd>偏移量,从头开始计算,单位为字节</dd> + <dt>value</dt> + <dd>设置的整数值</dd> + <dt> + <h3 id="返回">返回</h3> + + <p>{{jsxref("undefined")}}.</p> + </dt> +</dl> + +<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.setInt8(1, 3); +dataview.getInt8(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.setint8', 'DataView.prototype.setInt8')}}</td> + <td>{{Spec2('ES6')}}</td> + <td>Initial definition in an ECMA standard.</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + + + +<p>{{Compat("javascript.builtins.DataView.setInt8")}}</p> + +<h2 id="相关内容">相关内容</h2> + +<ul> + <li>{{jsxref("DataView")}}</li> + <li>{{jsxref("ArrayBuffer")}}</li> +</ul> |