From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../global_objects/dataview/buffer/index.html | 64 ++++++++ .../global_objects/dataview/bytelength/index.html | 70 +++++++++ .../global_objects/dataview/byteoffset/index.html | 67 +++++++++ .../global_objects/dataview/getbigint64/index.html | 91 +++++++++++ .../dataview/getbiguint64/index.html | 80 ++++++++++ .../global_objects/dataview/getfloat32/index.html | 94 ++++++++++++ .../global_objects/dataview/getfloat64/index.html | 91 +++++++++++ .../global_objects/dataview/getint16/index.html | 94 ++++++++++++ .../global_objects/dataview/getint32/index.html | 91 +++++++++++ .../global_objects/dataview/getint8/index.html | 86 +++++++++++ .../global_objects/dataview/getuint16/index.html | 94 ++++++++++++ .../global_objects/dataview/getuint32/index.html | 91 +++++++++++ .../global_objects/dataview/getuint8/index.html | 86 +++++++++++ .../reference/global_objects/dataview/index.html | 166 +++++++++++++++++++++ .../global_objects/dataview/prototype/index.html | 102 +++++++++++++ .../global_objects/dataview/setbigint64/index.html | 84 +++++++++++ .../dataview/setbiguint64/index.html | 83 +++++++++++ .../global_objects/dataview/setfloat32/index.html | 86 +++++++++++ .../global_objects/dataview/setfloat64/index.html | 86 +++++++++++ .../global_objects/dataview/setint16/index.html | 86 +++++++++++ .../global_objects/dataview/setint32/index.html | 86 +++++++++++ .../global_objects/dataview/setint8/index.html | 80 ++++++++++ .../global_objects/dataview/setuint16/index.html | 86 +++++++++++ .../global_objects/dataview/setuint32/index.html | 86 +++++++++++ .../global_objects/dataview/setuint8/index.html | 84 +++++++++++ 25 files changed, 2214 insertions(+) create mode 100644 files/zh-cn/web/javascript/reference/global_objects/dataview/buffer/index.html create mode 100644 files/zh-cn/web/javascript/reference/global_objects/dataview/bytelength/index.html create mode 100644 files/zh-cn/web/javascript/reference/global_objects/dataview/byteoffset/index.html create mode 100644 files/zh-cn/web/javascript/reference/global_objects/dataview/getbigint64/index.html create mode 100644 files/zh-cn/web/javascript/reference/global_objects/dataview/getbiguint64/index.html create mode 100644 files/zh-cn/web/javascript/reference/global_objects/dataview/getfloat32/index.html create mode 100644 files/zh-cn/web/javascript/reference/global_objects/dataview/getfloat64/index.html create mode 100644 files/zh-cn/web/javascript/reference/global_objects/dataview/getint16/index.html create mode 100644 files/zh-cn/web/javascript/reference/global_objects/dataview/getint32/index.html create mode 100644 files/zh-cn/web/javascript/reference/global_objects/dataview/getint8/index.html create mode 100644 files/zh-cn/web/javascript/reference/global_objects/dataview/getuint16/index.html create mode 100644 files/zh-cn/web/javascript/reference/global_objects/dataview/getuint32/index.html create mode 100644 files/zh-cn/web/javascript/reference/global_objects/dataview/getuint8/index.html create mode 100644 files/zh-cn/web/javascript/reference/global_objects/dataview/index.html create mode 100644 files/zh-cn/web/javascript/reference/global_objects/dataview/prototype/index.html create mode 100644 files/zh-cn/web/javascript/reference/global_objects/dataview/setbigint64/index.html create mode 100644 files/zh-cn/web/javascript/reference/global_objects/dataview/setbiguint64/index.html create mode 100644 files/zh-cn/web/javascript/reference/global_objects/dataview/setfloat32/index.html create mode 100644 files/zh-cn/web/javascript/reference/global_objects/dataview/setfloat64/index.html create mode 100644 files/zh-cn/web/javascript/reference/global_objects/dataview/setint16/index.html create mode 100644 files/zh-cn/web/javascript/reference/global_objects/dataview/setint32/index.html create mode 100644 files/zh-cn/web/javascript/reference/global_objects/dataview/setint8/index.html create mode 100644 files/zh-cn/web/javascript/reference/global_objects/dataview/setuint16/index.html create mode 100644 files/zh-cn/web/javascript/reference/global_objects/dataview/setuint32/index.html create mode 100644 files/zh-cn/web/javascript/reference/global_objects/dataview/setuint8/index.html (limited to 'files/zh-cn/web/javascript/reference/global_objects/dataview') diff --git a/files/zh-cn/web/javascript/reference/global_objects/dataview/buffer/index.html b/files/zh-cn/web/javascript/reference/global_objects/dataview/buffer/index.html new file mode 100644 index 0000000000..a8324d6dd2 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/dataview/buffer/index.html @@ -0,0 +1,64 @@ +--- +title: DataView.prototype.buffer +slug: Web/JavaScript/Reference/Global_Objects/DataView/buffer +translation_of: Web/JavaScript/Reference/Global_Objects/DataView/buffer +--- +
{{JSRef}}
+ +

 buffer 属性描述了在构造时被 DataView 引用的 {{jsxref("ArrayBuffer")}}。

+ +
{{EmbedInteractiveExample("pages/js/dataview-buffer.html")}}
+ + + +

语法

+ +
dataview.buffer
+ +

描述

+ +

buffer 属性是一个访问器(accessor)属性,它的 set 属性为 undefined,这意味着它是只读的。值在 DataView 被创建时就确定了,且不能改变。

+ +

示例

+ +

使用buffer属性

+ +
var buffer = new ArrayBuffer(8);
+var dataview = new DataView(buffer);
+dataview.buffer; // ArrayBuffer { byteLength: 8 }
+
+ +

规范

+ + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('ES6', '#sec-get-dataview.prototype.buffer', 'DataView.prototype.buffer')}}{{Spec2('ES6')}}Initial definition.
{{SpecName('ESDraft', '#sec-get-dataview.prototype.buffer', 'DataView.prototype.buffer')}}{{Spec2('ESDraft')}} 
+ +

浏览器兼容性

+ + + +

{{Compat("javascript.builtins.DataView.buffer")}}

+ +

相关链接

+ + diff --git a/files/zh-cn/web/javascript/reference/global_objects/dataview/bytelength/index.html b/files/zh-cn/web/javascript/reference/global_objects/dataview/bytelength/index.html new file mode 100644 index 0000000000..a581506c44 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/dataview/bytelength/index.html @@ -0,0 +1,70 @@ +--- +title: DataView.prototype.byteLength +slug: Web/JavaScript/Reference/Global_Objects/DataView/byteLength +translation_of: Web/JavaScript/Reference/Global_Objects/DataView/byteLength +--- +
{{JSRef}}
+ +

 byteLength 属性描述了视图从它的 {{jsxref("ArrayBuffer")}} 开始的字节长度。

+ +
{{EmbedInteractiveExample("pages/js/dataview-bytelength.html")}}
+ + + +

语法

+ +
dataview.byteLength
+ +

描述

+ +

byteLength 属性是一个获取(accessor)属性,它的 set 属性为 undefined,这意味着它是只读的。值在 DataView 被创建时就确定了,且不能改变。如果 DataView 没有指定偏移量或byteLength,那么被引用的 ArrayBuffer 的字节长度将被返回。

+ +

Examples

+ +

Using the byteLength property

+ +
var buffer = new ArrayBuffer(8);
+var dataview = new DataView(buffer);
+dataview.byteLength; // 8 (matches the byteLength of the buffer)
+
+var dataview2 = new DataView(buffer, 1, 5);
+dataview2.byteLength; // 5 (as specified when constructing the DataView)
+
+var dataview3 = new DataView(buffer, 2);
+dataview3.byteLength; // 6 (due to the offset of the constructed DataView)
+
+ +

规范

+ + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('ES6', '#sec-get-dataview.prototype.bytelength', 'DataView.prototype.byteLength')}}{{Spec2('ES6')}}Initial definition.
{{SpecName('ESDraft', '#sec-get-dataview.prototype.bytelength', 'DataView.prototype.byteLength')}}{{Spec2('ESDraft')}} 
+ +

浏览器兼容性

+ + + +

{{Compat("javascript.builtins.DataView.byteLength")}}

+ +

相关链接

+ + diff --git a/files/zh-cn/web/javascript/reference/global_objects/dataview/byteoffset/index.html b/files/zh-cn/web/javascript/reference/global_objects/dataview/byteoffset/index.html new file mode 100644 index 0000000000..9335006969 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/dataview/byteoffset/index.html @@ -0,0 +1,67 @@ +--- +title: DataView.prototype.byteOffset +slug: Web/JavaScript/Reference/Global_Objects/DataView/byteOffset +translation_of: Web/JavaScript/Reference/Global_Objects/DataView/byteOffset +--- +
{{JSRef}}
+ +

 byteOffset 属性描述了从 {{jsxref("ArrayBuffer")}} 开始的字节偏移量。

+ +
{{EmbedInteractiveExample("pages/js/dataview-byteoffset.html")}}
+ + + +

语法

+ +
dataview.byteOffset
+ +

描述

+ +

 byteOffset 属性是一个获取(accessor)属性,它的 set 属性为 undefined,这意味着它是只读的。值在 DataView 被创建时就确定了,且不能改变。

+ +

示例

+ +

使用 byteOffset 属性

+ +
var buffer = new ArrayBuffer(8);
+var dataview = new DataView(buffer);
+dataview.byteOffset; // 0 (没有指定偏移量)
+
+var dataview2 = new DataView(buffer, 3);
+dataview2.byteOffset; // 3 (在构造DataView时指定)
+
+ +

规范

+ + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('ES6', '#sec-get-dataview.prototype.byteoffset', 'DataView.prototype.byteOffset')}}{{Spec2('ES6')}}Initial definition.
{{SpecName('ESDraft', '#sec-get-dataview.prototype.byteoffset', 'DataView.prototype.byteOffset')}}{{Spec2('ESDraft')}} 
+ +

浏览器兼容性

+ + + +

{{Compat("javascript.builtins.DataView.byteOffset")}}

+ +

相关链接

+ + diff --git a/files/zh-cn/web/javascript/reference/global_objects/dataview/getbigint64/index.html b/files/zh-cn/web/javascript/reference/global_objects/dataview/getbigint64/index.html new file mode 100644 index 0000000000..cf90669761 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/dataview/getbigint64/index.html @@ -0,0 +1,91 @@ +--- +title: getBigInt64() +slug: Web/JavaScript/Reference/Global_Objects/DataView/getBigInt64 +tags: + - DataView + - JavaScript + - Prototype + - getBigInt64() + - 大整型 +translation_of: Web/JavaScript/Reference/Global_Objects/DataView/getBigInt64 +--- +
{{JSRef}}
+ +
+ +

getBigInt64() 方法从 {{jsxref("DataView")}}开始获取一个指定偏移量的有符号64位整数 (long long) 。

+ +
{{EmbedInteractiveExample("pages/js/dataview-getbigint64.html")}}
+ + + +

语法

+ +
dataview.getBigInt64(byteOffset [, littleEndian])
+ +

参数

+ +
+
byteOffset
+
偏移量,以字节为单位。指明视图开始读取数据的偏移量。
+
littleEndian
+
{{optional_inline}} 指明该64位整型数值的存储方式( {{Glossary("Endianness", "大小端模式")}}) 。 如果为 false 或 undefined, 则按大端方式读取数据。
+
+ +

返回值

+ +

一个 {{jsxref("BigInt")}}.

+ +

异常抛出

+ +
+
{{jsxref("RangeError")}}
+
如果 byteOffset 设置的偏移量超出了视图的范围,则抛出该异常。
+
+ +

简介

+ + + +

例子

+ +

使用 getBigInt64 方法

+ +
var buffer = new ArrayBuffer(8);
+var dataview = new DataView(buffer);
+dataview.getBigInt64(0); // 0n
+
+ +

规范

+ + + + + + + + + + + + + + +
规范版本规范状态注解      
DataView.prototype.getBigInt64 proposal
+ +

浏览器兼容性

+ + + +

{{Compat("javascript.builtins.DataView.getBigInt64")}}

+ +

另请参阅

+ + diff --git a/files/zh-cn/web/javascript/reference/global_objects/dataview/getbiguint64/index.html b/files/zh-cn/web/javascript/reference/global_objects/dataview/getbiguint64/index.html new file mode 100644 index 0000000000..d418df1366 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/dataview/getbiguint64/index.html @@ -0,0 +1,80 @@ +--- +title: DataView.prototype.getBigUint64() +slug: Web/JavaScript/Reference/Global_Objects/DataView/getBigUint64 +translation_of: Web/JavaScript/Reference/Global_Objects/DataView/getBigUint64 +--- +
{{JSRef}}
+ +

getBigUint64()方法,从{{jsxref("DataView")}}的指定偏移量位置获取一个无符号64位整数(unsigned long long)。

+ +
{{EmbedInteractiveExample("pages/js/dataview-getbiguint64.html")}}
+ + + +

语法

+ +
dataview.getBigUint64(byteOffset [, littleEndian])
+ +

参数

+ +
+
byteOffset
+
偏移量,按字节偏移,从DataView读取一个整数
+
littleEndian
+
{{optional_inline}} 指出64位整数以 {{Glossary("Endianness", "little- or big-endian")}} 类型存储. 如果值为 false or undefined, 读取一个大端数值.
+
+ +

返回值

+ +

A {{jsxref("BigInt")}}.

+ +

异常

+ +
+
{{jsxref("RangeError")}}
+
Thrown if the byteOffset is set such that it would read beyond the end of the view.
+
+ +

Description

+ +

There is no alignment constraint; multi-byte values may be fetched from any offset.

+ +

Examples

+ +

Using the getBigUint64 method

+ +
var buffer = new ArrayBuffer(8);
+var dataview = new DataView(buffer);
+dataview.getBigUint64(0); // 0n
+
+ +

Specifications

+ + + + + + + + + + + + + + +
SpecificationStatusComment
DataView.prototype.getBigUint64 proposal
+ +

Browser compatibility

+ + + +

{{Compat("javascript.builtins.DataView.getBigUint64")}}

+ +

See also

+ + diff --git a/files/zh-cn/web/javascript/reference/global_objects/dataview/getfloat32/index.html b/files/zh-cn/web/javascript/reference/global_objects/dataview/getfloat32/index.html new file mode 100644 index 0000000000..b43d4df38c --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/dataview/getfloat32/index.html @@ -0,0 +1,94 @@ +--- +title: DataView.prototype.getFloat32() +slug: Web/JavaScript/Reference/Global_Objects/DataView/getFloat32 +tags: + - DataView + - getFloat32 +translation_of: Web/JavaScript/Reference/Global_Objects/DataView/getFloat32 +--- +
{{JSRef}}
+ +

getFloat32()方法从相对于{{jsxref("DataView")}} 的起始位置偏移 n 个字节处获取一个32-bit浮点数(单精度浮点数,4个字节).

+ +
{{EmbedInteractiveExample("pages/js/dataview-getfloat32.html")}}
+ + + +

语法

+ +
dataview.getFloat32(byteOffset [, littleEndian])
+ +

参数

+ +
+
byteOffset
+
偏移量, 单位为字节, 为从视图的开始位置到读取数值的位置的偏移。
+
littleEndian
+
{{optional_inline}} 表示这个32位浮点数是否以 {{Glossary("Endianness", "little- or big-endian")}} 格式存储,如果设置为 false 或者不指定,将用big-endian格式读取数值。
+
+ +

返回

+ +
+
一个带符号的32位浮点数。
+
+ +

抛出错误

+ +
+
{{jsxref("RangeError")}}
+
如果byteOffset 设置导致读数值时超出了视图的末尾就会抛出错误。
+
+ +

说明

+ +
+
没有对齐约束; 多字节值可以从任何偏移处获取。
+
+ +

例子

+ +
var buffer = new ArrayBuffer(8);
+var dataview = new DataView(buffer);
+dataview.getFloat32(1); // 0
+
+ +

规范

+ + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Typed Array')}}{{Spec2('Typed Array')}}Superseded by ECMAScript 6.
{{SpecName('ES6', '#sec-dataview.prototype.getfloat32', 'DataView.prototype.getFloat32')}}{{Spec2('ES6')}}Initial definition in an ECMA standard.
{{SpecName('ESDraft', '#sec-dataview.prototype.getfloat32', 'DataView.prototype.getFloat32')}}{{Spec2('ESDraft')}}
+ +

浏览器支持

+ + + +

{{Compat("javascript.builtins.DataView.getFloat32")}}

+ +

另见

+ + diff --git a/files/zh-cn/web/javascript/reference/global_objects/dataview/getfloat64/index.html b/files/zh-cn/web/javascript/reference/global_objects/dataview/getfloat64/index.html new file mode 100644 index 0000000000..885acb9421 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/dataview/getfloat64/index.html @@ -0,0 +1,91 @@ +--- +title: DataView.prototype.getFloat64() +slug: Web/JavaScript/Reference/Global_Objects/DataView/getFloat64 +translation_of: Web/JavaScript/Reference/Global_Objects/DataView/getFloat64 +--- +
{{JSRef}}
+ +

getFloat64()方法DataView相对于起始位置偏移 n 个字节处开始,获取一个64-bit数(双精度浮点型,8个字节).

+ +
{{EmbedInteractiveExample("pages/js/dataview-getfloat64.html")}}
+ + + +

语法

+ +
dataview.getFloat64(byteOffset [, littleEndian])
+ +

参数

+ +
+
byteOffset
+
偏移量, 单位为字节, 从头开始计算.
+
littleEndian
+
{{optional_inline}} Indicates whether the 64-bit float is stored in {{Glossary("Endianness", "little- or big-endian")}} format. If false or undefined, a big-endian value is read.
+
+ +

返回

+ +
+
一个双精度浮点型64位数.
+
+ +

抛出错误

+ +
+
{{jsxref("RangeError")}}
+
如果byteOffset超出了视图能储存的值,就会抛出错误.
+
+ +

描述

+ +
+
没有对齐约束; 多字节值可以从任何偏移量获取.
+
+ +

例子

+ +
var buffer = new ArrayBuffer(8);
+var dataview = new DataView(buffer);
+dataview.getFloat64(1); // 0
+
+ +

规范

+ + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Typed Array')}}{{Spec2('Typed Array')}}Superseded by ECMAScript 6.
{{SpecName('ES6', '#sec-dataview.prototype.getfloat64', 'DataView.prototype.getFloat64')}}{{Spec2('ES6')}}Initial definition in ECMA standard.
{{SpecName('ESDraft', '#sec-dataview.prototype.getfloat64', 'DataView.prototype.getFloat64')}}{{Spec2('ESDraft')}}
+ +

浏览器支持

+ + + +

{{Compat("javascript.builtins.DataView.getFloat64")}}

+ +

另见

+ + diff --git a/files/zh-cn/web/javascript/reference/global_objects/dataview/getint16/index.html b/files/zh-cn/web/javascript/reference/global_objects/dataview/getint16/index.html new file mode 100644 index 0000000000..060f88b722 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/dataview/getint16/index.html @@ -0,0 +1,94 @@ +--- +title: DataView.prototype.getInt16() +slug: Web/JavaScript/Reference/Global_Objects/DataView/getInt16 +tags: + - 类型化 + - 类型化数组 +translation_of: Web/JavaScript/Reference/Global_Objects/DataView/getInt16 +--- +
{{JSRef}}
+ +

getInt16()方法{{jsxref("DataView")}}相对于起始位置偏移 n 个字节处开始,获取一个16-bit数(短整型,2个字节).

+ +
{{EmbedInteractiveExample("pages/js/dataview-getint16.html")}}
+ + + +

语法

+ +
dataview.getInt16(byteOffset [, littleEndian])
+ +

参数

+ +
+
byteOffset
+
偏移量, 单位为字节, 从头开始计算.
+
littleEndian
+
{{optional_inline}} 表示该 16 位整数是否以 {{Glossary("Endianness", "little- or big-endian")}} 格式存储的(就是使用的字节序格式,具体参考链接页面);如果传入的值为 true,就表示使用 little-endian(低字节序),如果传入的值为 false 或者 undefined,则会使用 big-endian(高字节序) 方式读值。
+
+ +

返回

+ +
+
一个短整型16位数.
+
+ +

抛出错误

+ +
+
{{jsxref("RangeError")}}
+
如果byteOffset超出了视图能储存的值,就会抛出错误.
+
+ +

描述

+ +
+
 没有对齐约束; 多字节值可以从任何偏移量获取.
+
+ +

例子

+ +
var buffer = new ArrayBuffer(8);
+var dataview = new DataView(buffer);
+dataview.getInt16(1); // 0
+
+ +

规范

+ + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Typed Array')}}{{Spec2('Typed Array')}}Superseded by ECMAScript 6.
{{SpecName('ES6', '#sec-dataview.prototype.getint16', 'DataView.prototype.getInt16')}}{{Spec2('ES6')}}Initial definition in an ECMA standard.
{{SpecName('ESDraft', '#sec-dataview.prototype.getint16', 'DataView.prototype.getInt16')}}{{Spec2('ESDraft')}}
+ +

浏览器支持

+ + + +

{{Compat("javascript.builtins.DataView.getInt16")}}

+ +

另见

+ + diff --git a/files/zh-cn/web/javascript/reference/global_objects/dataview/getint32/index.html b/files/zh-cn/web/javascript/reference/global_objects/dataview/getint32/index.html new file mode 100644 index 0000000000..616d2b1977 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/dataview/getint32/index.html @@ -0,0 +1,91 @@ +--- +title: DataView.prototype.getInt32() +slug: Web/JavaScript/Reference/Global_Objects/DataView/getInt32 +translation_of: Web/JavaScript/Reference/Global_Objects/DataView/getInt32 +--- +
{{JSRef}}
+ +

getInt32()方法DataView相对于起始位置偏移 n 个字节处开始,获取一个32-bit数(长整型,4个字节).

+ +
{{EmbedInteractiveExample("pages/js/dataview-getint32.html")}}
+ + + +

语法

+ +
dataview.getInt32(byteOffset [, littleEndian])
+ +

参数

+ +
+
byteOffset
+
偏移量, 单位为字节, 从头开始计算.
+
littleEndian
+
{{optional_inline}} Indicates whether the 32-bit int is stored in {{Glossary("Endianness", "little- or big-endian")}} format. If false or undefined, a big-endian value is read.
+
+ +

返回

+ +
+
一个长整型32位数.
+
+ +

抛出错误

+ +
+
{{jsxref("RangeError")}}
+
如果byteOffset超出了视图能储存的值,就会抛出错误.
+
+ +

描述

+ +
+
 没有对齐约束; 多字节值可以从任何偏移量获取.
+
+ +

例子

+ +
var buffer = new ArrayBuffer(8);
+var dataview = new DataView(buffer);
+dataview.getInt32(1); // 0
+
+ +

规范

+ + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Typed Array')}}{{Spec2('Typed Array')}}Superseded by ECMAScript 6.
{{SpecName('ES6', '#sec-dataview.prototype.getint32', 'DataView.prototype.getInt32')}}{{Spec2('ES6')}}Initial definition in an ECMA standard.
{{SpecName('ESDraft', '#sec-dataview.prototype.getint32', 'DataView.prototype.getInt32')}}{{Spec2('ESDraft')}}
+ +

浏览器支持

+ + + +

{{Compat("javascript.builtins.DataView.getInt32")}}

+ +

另见

+ + diff --git a/files/zh-cn/web/javascript/reference/global_objects/dataview/getint8/index.html b/files/zh-cn/web/javascript/reference/global_objects/dataview/getint8/index.html new file mode 100644 index 0000000000..0a8a5da6a2 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/dataview/getint8/index.html @@ -0,0 +1,86 @@ +--- +title: DataView.prototype.getInt8() +slug: Web/JavaScript/Reference/Global_Objects/DataView/getInt8 +tags: + - 类型化 + - 类型化数组 +translation_of: Web/JavaScript/Reference/Global_Objects/DataView/getInt8 +--- +
{{JSRef}}
+ +

getInt8()方法{{jsxref("DataView")}}相对于起始位置偏移 n 个字节处开始,获取一个有符号的 8-bit 整数(一个字节)。

+ +
{{EmbedInteractiveExample("pages/js/dataview-getint8.html")}}
+ + + +

语法

+ +
dataview.getInt8(byteOffset)
+ +

参数

+ +
+
byteOffset
+
偏移量, 单位为字节, 从起始位置开始计算.
+
+ +

抛出错误

+ +
+
{{jsxref("RangeError")}}
+
如果byteOffset超出了视图能储存的值,就会抛出错误.
+
+ +

描述

+ +
+
 没有对齐约束; 多字节值可以从任何偏移量获取.
+
+ +

例子

+ +
var buffer = new ArrayBuffer(8);
+var dataview = new DataView(buffer);
+dataview.getInt8(1); // 0
+
+ +

规范

+ + + + + + + + + + + + + + + + + + + + + + + + +
规范状态说明
{{SpecName('Typed Array')}}{{Spec2('Typed Array')}}Superseded by ECMAScript 6.
{{SpecName('ES6', '#sec-dataview.prototype.getint8', 'DataView.prototype.getInt8')}}{{Spec2('ES6')}}Initial definition in an ECMA standard.
{{SpecName('ESDraft', '#sec-dataview.prototype.getint8', 'DataView.prototype.getInt8')}}{{Spec2('ESDraft')}}
+ +

浏览器兼容性

+ + + +

{{Compat("javascript.builtins.DataView.getInt8")}}

+ +

相关内容

+ + diff --git a/files/zh-cn/web/javascript/reference/global_objects/dataview/getuint16/index.html b/files/zh-cn/web/javascript/reference/global_objects/dataview/getuint16/index.html new file mode 100644 index 0000000000..6ed5b252da --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/dataview/getuint16/index.html @@ -0,0 +1,94 @@ +--- +title: DataView.prototype.getUint16() +slug: Web/JavaScript/Reference/Global_Objects/DataView/getUint16 +tags: + - 类型化 + - 类型化数组 +translation_of: Web/JavaScript/Reference/Global_Objects/DataView/getUint16 +--- +
{{JSRef}}
+ +

getUint16()方法DataView相对于起始位置偏移 n 个字节处开始,获取一个16-bit数(无符号短整型,2个字节).

+ +
{{EmbedInteractiveExample("pages/js/dataview-getuint16.html")}}
+ + + +

语法

+ +
dataview.getUint16(byteOffset [, littleEndian])
+ +

参数

+ +
+
byteOffset
+
偏移量, 单位为字节, 从头开始计算.
+
littleEndian
+
{{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 read.
+
+ +

返回

+ +
+
一个无符号短整型16位数.
+
+ +

抛出错误

+ +
+
{{jsxref("RangeError")}}
+
如果byteOffset超出了视图能储存的值,就会抛出错误.
+
+ +

描述

+ +
+
没有对齐约束; 多字节值可以从任何偏移量获取.
+
+ +

例子

+ +
var buffer = new ArrayBuffer(8);
+var dataview = new DataView(buffer);
+dataview.getUint16(1); // 0
+
+ +

规范

+ + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Typed Array')}}{{Spec2('Typed Array')}}Superseded by ECMAScript 6.
{{SpecName('ES6', '#sec-dataview.prototype.getuint16', 'DataView.prototype.getUint16')}}{{Spec2('ES6')}}Initial definition in an ECMA standard.
{{SpecName('ESDraft', '#sec-dataview.prototype.getuint16', 'DataView.prototype.getUint16')}}{{Spec2('ESDraft')}}
+ +

浏览器支持

+ + + +

{{Compat("javascript.builtins.DataView.getUint16")}}

+ +

另见

+ + diff --git a/files/zh-cn/web/javascript/reference/global_objects/dataview/getuint32/index.html b/files/zh-cn/web/javascript/reference/global_objects/dataview/getuint32/index.html new file mode 100644 index 0000000000..3affb0312a --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/dataview/getuint32/index.html @@ -0,0 +1,91 @@ +--- +title: DataView.prototype.getUint32() +slug: Web/JavaScript/Reference/Global_Objects/DataView/getUint32 +translation_of: Web/JavaScript/Reference/Global_Objects/DataView/getUint32 +--- +
{{JSRef}}
+ +

getUint32()方法DataView相对于起始位置偏移 n 个字节处开始,获取一个32-bit数(无符号长整型,4个字节).

+ +
{{EmbedInteractiveExample("pages/js/dataview-getuint32.html")}}
+ + + +

语法

+ +
dataview.getUint32(byteOffset [, littleEndian])
+ +

参数

+ +
+
byteOffset
+
偏移量, 单位为字节, 从头开始计算.
+
littleEndian
+
{{optional_inline}} Indicates whether the 32-bit int is stored in {{Glossary("Endianness", "little- or big-endian")}} format. If false or undefined, a big-endian value is read.
+
+ +

返回

+ +
+
一个无符号长整型32位数.
+
+ +

抛出错误

+ +
+
{{jsxref("RangeError")}}
+
如果byteOffset超出了视图能储存的值,就会抛出错误.
+
+ +

描述

+ +
+
没有对齐约束; 多字节值可以从任何偏移量获取.
+
+ +

例子

+ +
var buffer = new ArrayBuffer(8);
+var dataview = new DataView(buffer);
+dataview.getUint32(1); // 0
+
+ +

规范

+ + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Typed Array')}}{{Spec2('Typed Array')}}Superseded by ECMAScript 6.
{{SpecName('ES6', '#sec-dataview.prototype.getuint32', 'DataView.prototype.getUint32')}}{{Spec2('ES6')}}Initial definition in an ECMA standard.
{{SpecName('ESDraft', '#sec-dataview.prototype.getuint32', 'DataView.prototype.getUint32')}}{{Spec2('ESDraft')}}
+ +

浏览器支持

+ + + +

{{Compat("javascript.builtins.DataView.getUint32")}}

+ +

另见

+ + diff --git a/files/zh-cn/web/javascript/reference/global_objects/dataview/getuint8/index.html b/files/zh-cn/web/javascript/reference/global_objects/dataview/getuint8/index.html new file mode 100644 index 0000000000..4e26ade311 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/dataview/getuint8/index.html @@ -0,0 +1,86 @@ +--- +title: DataView.prototype.getUint8() +slug: Web/JavaScript/Reference/Global_Objects/DataView/getUint8 +tags: + - 类型化 + - 类型化数组 +translation_of: Web/JavaScript/Reference/Global_Objects/DataView/getUint8 +--- +
{{JSRef}}
+ +

getUint8()方法{{jsxref("DataView")}}相对于起始位置偏移 n 个字节处开始,获取一个无符号的8-bit整数(一个字节).

+ +
{{EmbedInteractiveExample("pages/js/dataview-getuint8.html")}}
+ + + +

语法

+ +
dataview.getUint8(byteOffset)
+ +

参数

+ +
+
byteOffset
+
偏移量, 单位为字节, 从头开始计算.
+
+ +

抛出错误

+ +
+
{{jsxref("RangeError")}}
+
如果byteOffset超出了视图能储存的值,就会抛出错误.
+
+ +

描述

+ +
+
 没有对齐约束; 多字节值可以从任何偏移量获取.
+
+ +

例子

+ +
var buffer = new ArrayBuffer(8);
+var dataview = new DataView(buffer);
+dataview.getUint8(1); // 0
+
+ +

规范

+ + + + + + + + + + + + + + + + + + + + + + + + +
规范状态说明
{{SpecName('Typed Array')}}{{Spec2('Typed Array')}}Superseded by ECMAScript 6.
{{SpecName('ES6', '#sec-dataview.prototype.getuint8', 'DataView.prototype.getUint8')}}{{Spec2('ES6')}}Initial definition in an ECMA standard.
{{SpecName('ESDraft', '#sec-dataview.prototype.getuint8', 'DataView.prototype.getUint8')}}{{Spec2('ESDraft')}}
+ +

浏览器兼容性

+ + + +

{{Compat("javascript.builtins.DataView.getUint8")}}

+ +

相关内容

+ + diff --git a/files/zh-cn/web/javascript/reference/global_objects/dataview/index.html b/files/zh-cn/web/javascript/reference/global_objects/dataview/index.html new file mode 100644 index 0000000000..7bd1755475 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/dataview/index.html @@ -0,0 +1,166 @@ +--- +title: DataView +slug: Web/JavaScript/Reference/Global_Objects/DataView +tags: + - DataView + - JavaScript + - TypedArrays + - 构造器 +translation_of: Web/JavaScript/Reference/Global_Objects/DataView +--- +
{{JSRef}}
+ +

DataView 视图是一个可以从 二进制{{jsxref("ArrayBuffer")}} 对象中读写多种数值类型的底层接口,使用它时,不用考虑不同平台的字节序问题。

+ +
{{EmbedInteractiveExample("pages/js/dataview-constructor.html")}}
+ + + +

语法

+ +
new DataView(buffer [, byteOffset [, byteLength]])
+ +

参数

+ +
+
buffer
+
一个 已经存在的{{jsxref("ArrayBuffer")}} 或 {{jsxref("SharedArrayBuffer")}} {{experimental_inline}} 对象,DataView 对象的数据源。
+
byteOffset {{optional_inline}}
+
DataView 对象的第一个字节在 buffer 中的字节偏移。如果未指定,则默认从第一个字节开始。
+
byteLength {{optional_inline}}
+
此 DataView 对象的字节长度。如果未指定,这个视图的长度将匹配buffer的长度。
+
+ +

返回值

+ +

一个表示指定数据缓存区的新DataView 对象。(这句话也许不是非常有助于说明清楚)

+ +

你可以把返回的对象想象成一个二进制字节缓存区 array buffer 的“解释器”——它知道如何在读取或写入时正确地转换字节码。这意味着它能在二进制层面处理整数与浮点转化、字节顺序等其他有关的细节问题。

+ +

异常

+ +
+
{{jsxref("RangeError")}}
+
如果 byteOffset 或者 byteLength 参数的值导致视图超出了 buffer 的结束位置就会抛出此异常。
+ 例如,假设 buffer (缓冲对象)是 16 字节长度,byteOffset 参数为 8,byteLength 参数为 10,这个错误就会抛出,这是因为结果视图试图超出 buffer 对象的总长度 2 个字节。
+
+ +

描述

+ +

Endianness(字节序)

+ +

需要多个字节来表示的数值,在存储时其字节在内存中的相对顺序依据平台架构的不同而不同,参照 {{Glossary("Endianness")}}。而使用 DataView 的访问函数时,不需要考虑平台架构中所使用的是哪种字节序。

+ +
var littleEndian = (function() {
+  var buffer = new ArrayBuffer(2);
+  new DataView(buffer).setInt16(0, 256, true /* 设置值时,使用小端字节序 */);
+  // Int16Array 使用系统字节序(由此可以判断系统字节序是否为小端字节序)
+  return new Int16Array(buffer)[0] === 256;
+})();
+console.log(littleEndian); // 返回 true 或 false
+
+ +

64 位整数值

+ +

因为 JavaScript 目前不包含对 64 位整数值支持的标准,所以 DataView 不提供原生的 64 位操作。作为变通,您可以实现自己的 getUint64() 函数,以获得精度高达 {{jsxref("Number.MAX_SAFE_INTEGER")}} 的值,可以满足某些特定情况的需求。

+ +
function getUint64(dataview, byteOffset, littleEndian) {
+  // 将 64 位整数值分成两份 32 位整数值
+  const left =  dataview.getUint32(byteOffset, littleEndian);
+  const right = dataview.getUint32(byteOffset+4, littleEndian);
+
+  // 合并两个 32 位整数值
+  const combined = littleEndian? left + 2**32*right : 2**32*left + right;
+
+  if (!Number.isSafeInteger(combined))
+    console.warn(combined, 'exceeds MAX_SAFE_INTEGER. Precision may be lost');
+
+  return combined;
+}
+
+ +

或者,如果需要填满 64 位,可以创建一个 {{jsxref("BigInt")}}。此外,尽管原生 BigInt 要比用户端的库中模拟的 BigInt 快得多,但在 JavaScript 中,BigInt 总是比 32 位整数慢得多,这是因为 BigInt 的大小是可变的。

+ +
const BigInt = window.BigInt, bigThirtyTwo = BigInt(32), bigZero = BigInt(0);
+function getUint64BigInt(dataview, byteOffset, littleEndian) {
+  // 将 64 位整数值分成两份 32 位整数值
+  const left = BigInt(dataview.getUint32(byteOffset|0, !!littleEndian)>>>0);
+  const right = BigInt(dataview.getUint32((byteOffset|0) + 4|0, !!littleEndian)>>>0);
+
+  // 合并两个 32 位整数值并返回
+  return littleEndian ? (right<<bigThirtyTwo)|left : (left<<bigThirtyTwo)|right;
+}
+ +

属性

+ +

所有 DataView 实例都继承自 {{jsxref("DataView.prototype")}},并且允许向 DataView 对象中添加额外属性。

+ +
{{page('zh-CN/Web/JavaScript/Reference/Global_Objects/DataView/prototype', '属性')}}
+ +

方法

+ +
{{page('zh-CN/Web/JavaScript/Reference/Global_Objects/DataView/prototype', '方法')}}
+ +

示例

+ +
var buffer = new ArrayBuffer(16);
+var view = new DataView(buffer, 0);
+
+view.setInt16(1, 42);
+view.getInt16(1); // 42
+
+ +

规范

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
规范名称状态注释
{{SpecName('ESDraft', '#sec-dataview-constructor', 'DataView')}}{{Spec2('ESDraft')}}
{{SpecName('ES6', '#sec-dataview-constructor', 'DataView')}}{{Spec2('ES6')}}ECMA 标准中的初始版本
{{SpecName('Typed Array')}}{{Spec2('Typed Array')}}Superseded by ECMAScript 6
+ +

浏览器兼容性

+ + + +

{{Compat("javascript.builtins.DataView")}}

+ +

兼容性提示

+ +

从 FireFox 40 开始,DataView 对象需要通过 {{jsxref("Operators/new", "new")}} 操作符来构造。如果不使用 new 而是直接将 DataView() 作为函数调用的话,会抛出 {{jsxref("TypeError")}} 异常。

+ +
var dv = DataView(buffer, 0);
+// 抛出异常,错误信息翻译为:禁止在不用 new 的情况下直接调用 DataView 的构造函数。
+// TypeError: calling a builtin DataView constructor without new is forbidden
+ +
var dv = new DataView(buffer, 0);
+ +

请参阅

+ + diff --git a/files/zh-cn/web/javascript/reference/global_objects/dataview/prototype/index.html b/files/zh-cn/web/javascript/reference/global_objects/dataview/prototype/index.html new file mode 100644 index 0000000000..84488ad734 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/dataview/prototype/index.html @@ -0,0 +1,102 @@ +--- +title: DataView.prototype +slug: Web/JavaScript/Reference/Global_Objects/DataView/prototype +tags: + - DataView属性 +translation_of: Web/JavaScript/Reference/Global_Objects/DataView +--- +
{{JSRef}}
+ +

DataView.prototype 表示{{jsxref("DataView")}}的原型

+ +
{{js_property_attributes(0,0,0)}}
+ +

描述

+ +

DataView 的实例从DataView.prototype继承。就像所有的构造器,你可以修改原型来改变生成的DataView实例。

+ +

属性

+ +
+
{{jsxref("DataView.prototype.constructor")}}
+
指定用来生成原型的构造函数.初始化值是标准内置DataView构造器.
+
{{jsxref("DataView.prototype.buffer")}} {{readonlyInline}}
+
被视图引入的{{jsxref("ArrayBuffer")}}.创建实例的时候已固化因此是只读的.
+
{{jsxref("DataView.prototype.byteLength")}} {{readonlyInline}}
+
从 {{jsxref("ArrayBuffer")}}中读取的字节长度. 创建实例的时候已固化因此是只读的.
+
{{jsxref("DataView.prototype.byteOffset")}} {{readonlyInline}}
+
从 {{jsxref("ArrayBuffer")}}读取时的偏移字节长度. 创建实例的时候已固化因此是只读的.
+
+ +

方法

+ +

+ +
+
{{jsxref("DataView.prototype.getInt8()")}}
+
{{jsxref("DataView")}}起始位置以byte为计数的指定偏移量(byteOffset)处获取一个8-bit数(一个字节).
+
{{jsxref("DataView.prototype.getUint8()")}}
+
{{jsxref("DataView")}}起始位置以byte为计数的指定偏移量(byteOffset)处获取一个8-bit数(无符号字节).
+
{{jsxref("DataView.prototype.getInt16()")}}
+
{{jsxref("DataView")}}起始位置以byte为计数的指定偏移量(byteOffset)处获取一个16-bit数(短整型).
+
{{jsxref("DataView.prototype.getUint16()")}}
+
{{jsxref("DataView")}}起始位置以byte为计数的指定偏移量(byteOffset)处获取一个16-bit数(无符号短整型).
+
{{jsxref("DataView.prototype.getInt32()")}}
+
{{jsxref("DataView")}}起始位置以byte为计数的指定偏移量(byteOffset)处获取一个32-bit数(长整型).
+
{{jsxref("DataView.prototype.getUint32()")}}
+
{{jsxref("DataView")}}起始位置以byte为计数的指定偏移量(byteOffset)处获取一个32-bit数(无符号长整型).
+
{{jsxref("DataView.prototype.getFloat32()")}}
+
{{jsxref("DataView")}}起始位置以byte为计数的指定偏移量(byteOffset)处获取一个32-bit数(浮点型).
+
{{jsxref("DataView.prototype.getFloat64()")}}
+
{{jsxref("DataView")}}起始位置以byte为计数的指定偏移量(byteOffset)处获取一个64-bit数(双精度浮点型).
+
+ +

+ +
+
{{jsxref("DataView.prototype.setInt8()")}}
+
{{jsxref("DataView")}}起始位置以byte为计数的指定偏移量(byteOffset)处储存一个8-bit数(一个字节).
+
{{jsxref("DataView.prototype.setUint8()")}}
+
{{jsxref("DataView")}}起始位置以byte为计数的指定偏移量(byteOffset)处储存一个8-bit数(无符号字节).
+
{{jsxref("DataView.prototype.setInt16()")}}
+
{{jsxref("DataView")}}起始位置以byte为计数的指定偏移量(byteOffset)处储存一个16-bit数(短整型).
+
{{jsxref("DataView.prototype.setUint16()")}}
+
{{jsxref("DataView")}}起始位置以byte为计数的指定偏移量(byteOffset)处储存一个16-bit数(无符号短整型).
+
{{jsxref("DataView.prototype.setInt32()")}}
+
{{jsxref("DataView")}}起始位置以byte为计数的指定偏移量(byteOffset)处储存一个32-bit数(长整型).
+
{{jsxref("DataView.prototype.setUint32()")}}
+
{{jsxref("DataView")}}起始位置以byte为计数的指定偏移量(byteOffset)处储存一个32-bit数(无符号长整型).
+
{{jsxref("DataView.prototype.setFloat32()")}}
+
{{jsxref("DataView")}}起始位置以byte为计数的指定偏移量(byteOffset)处储存一个32-bit数(浮点型).
+
{{jsxref("DataView.prototype.setFloat64()")}}
+
{{jsxref("DataView")}}起始位置以byte为计数的指定偏移量(byteOffset)处储存一个64-bit数(双精度浮点型).
+
+ +

规范

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('ES6', '#sec-dataview.prototype', 'DataView.prototype')}}{{Spec2('ES6')}}Initial definition.
+ +

浏览器支持

+ + + +

{{Compat("javascript.builtins.DataView.prototype")}}

+ +

另见

+ + diff --git a/files/zh-cn/web/javascript/reference/global_objects/dataview/setbigint64/index.html b/files/zh-cn/web/javascript/reference/global_objects/dataview/setbigint64/index.html new file mode 100644 index 0000000000..5e9b6596d4 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/dataview/setbigint64/index.html @@ -0,0 +1,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 +--- +
{{JSRef}}
+ +

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

+ +
{{EmbedInteractiveExample("pages/js/dataview-setbigint64.html")}}
+ + + +

语法

+ +
dataview.setBigInt64(byteOffset, value [, littleEndian])
+ +

参数说明

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

返回值

+ +

{{jsxref("undefined")}}.

+ +

抛出的错误

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

例子

+ +

使用 setBigInt64 方法

+ +
var buffer = new ArrayBuffer(8);
+var dataview = new DataView(buffer);
+dataview.setBigInt64(0, 3n);
+dataview.getBigInt64(0); // 3n
+
+ +

相关规范

+ + + + + + + + + + + + + + +
规范状态解释
{{SpecName('ESDraft', '#sec-dataview.prototype.setbigint64', 'DataView.prototype.setBigInt64()')}}{{Spec2('ESDraft')}}    
+ +

浏览器兼容性

+ + + +

{{Compat("javascript.builtins.DataView.setBigInt64")}}

+ +

请参阅

+ + diff --git a/files/zh-cn/web/javascript/reference/global_objects/dataview/setbiguint64/index.html b/files/zh-cn/web/javascript/reference/global_objects/dataview/setbiguint64/index.html new file mode 100644 index 0000000000..bd2bfef8f4 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/dataview/setbiguint64/index.html @@ -0,0 +1,83 @@ +--- +title: DataView.prototype.setBigUint64() +slug: Web/JavaScript/Reference/Global_Objects/DataView/setBigUint64 +tags: + - BigInt + - DataView + - setBigUint64 +translation_of: Web/JavaScript/Reference/Global_Objects/DataView/setBigUint64 +--- +
{{JSRef}}
+ +

setBigUint64() 方法在距DataView 的起始位置的指定字节偏移处存储一个无符号的64位整数(unsigned  long long类型)值。

+ +
{{EmbedInteractiveExample("pages/js/dataview-setbiguint64.html")}}
+ + + +

语法

+ +
dataview.setBigUint64(byteOffset, value [, littleEndian])
+ +

参数说明

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

返回值

+ +

{{jsxref("undefined")}}.

+ +

抛出的错误

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

例子

+ +

使用 setBigUint64 方法

+ +
var buffer = new ArrayBuffer(8);
+var dataview = new DataView(buffer);
+dataview.setBigUint64(0, 3n);
+dataview.getBigUint64(0); // 3n
+
+ +

相关规范 

+ + + + + + + + + + + + + + +
规范状态解释
{{SpecName('ESDraft', '#sec-dataview.prototype.setbiguint64', 'DataView.prototype.setBigUint64()')}}{{Spec2('ESDraft')}}
+ +

浏览器兼容性

+ + + +

{{Compat("javascript.builtins.DataView.setBigUint64")}}

+ +

请参阅

+ + diff --git a/files/zh-cn/web/javascript/reference/global_objects/dataview/setfloat32/index.html b/files/zh-cn/web/javascript/reference/global_objects/dataview/setfloat32/index.html new file mode 100644 index 0000000000..418718aef2 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/dataview/setfloat32/index.html @@ -0,0 +1,86 @@ +--- +title: DataView.prototype.setFloat32() +slug: Web/JavaScript/Reference/Global_Objects/DataView/setFloat32 +translation_of: Web/JavaScript/Reference/Global_Objects/DataView/setFloat32 +--- +
{{JSRef}}
+ +

setFloat32()DataView起始位置以byte为计数的指定偏移量(byteOffset)处储存一个32-bit数(浮点型).

+ +

{{EmbedInteractiveExample("pages/js/dataview-setfloat32.html")}}

+ + + +

语法

+ +
dataview.setFloat32(byteOffset, value [, littleEndian])
+ +

参数

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

返回

+ +

{{jsxref("undefined")}}.

+ +

抛出错误

+ +
+
{{jsxref("RangeError")}}
+
如果byteOffset超出了视图能储存的值,就会抛出错误.
+
+ +

例子

+ +
var buffer = new ArrayBuffer(8);
+var dataview = new DataView(buffer);
+dataview.setFloat32(1, 3);
+dataview.getFloat32(1); // 3
+
+ +

规范

+ + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Typed Array')}}{{Spec2('Typed Array')}}Superseded by ECMAScript 6.
{{SpecName('ES6', '#sec-dataview.prototype.setfloat32', 'DataView.prototype.setFloat32')}}{{Spec2('ES6')}}Initial definition in an ECMA standard.
{{SpecName('ESDraft', '#sec-dataview.prototype.setfloat32', 'DataView.prototype.setFloat32')}}{{Spec2('ESDraft')}} 
+ +

浏览器支持

+ + + +

{{Compat("javascript.builtins.DataView.setFloat32")}}

+ +

相关内容

+ + diff --git a/files/zh-cn/web/javascript/reference/global_objects/dataview/setfloat64/index.html b/files/zh-cn/web/javascript/reference/global_objects/dataview/setfloat64/index.html new file mode 100644 index 0000000000..1f46fddbf0 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/dataview/setfloat64/index.html @@ -0,0 +1,86 @@ +--- +title: DataView.prototype.setFloat64() +slug: Web/JavaScript/Reference/Global_Objects/DataView/setFloat64 +translation_of: Web/JavaScript/Reference/Global_Objects/DataView/setFloat64 +--- +
{{JSRef}}
+ +

setFloat64()DataView起始位置以byte为计数的指定偏移量(byteOffset)处储存一个64-bit数(双精度浮点型).

+ +
{{EmbedInteractiveExample("pages/js/dataview-setfloat64.html")}}
+ + + +

语法

+ +
dataview.setFloat64(byteOffset, value [, littleEndian])
+ +

参数

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

返回

+ +

{{jsxref("undefined")}}.

+ +

抛出错误

+ +
+
{{jsxref("RangeError")}}
+
如果byteOffset超出了视图能储存的值,就会抛出错误.
+
+ +

例子

+ +
var buffer = new ArrayBuffer(8);
+var dataview = new DataView(buffer);
+dataview.setFloat64(0, 3);
+dataview.getFloat64(0); // 3
+
+ +

规范

+ + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Typed Array')}}{{Spec2('Typed Array')}}Superseded by ECMAScript 6.
{{SpecName('ES6', '#sec-dataview.prototype.setfloat64', 'DataView.prototype.setFloat64')}}{{Spec2('ES6')}}Initial definition in an ECMA standard.
{{SpecName('ESDraft', '#sec-dataview.prototype.setfloat64', 'DataView.prototype.setFloat64')}}{{Spec2('ESDraft')}} 
+ +

浏览器支持

+ + + +

{{Compat("javascript.builtins.DataView.setFloat64")}}

+ +

相关内容

+ + diff --git a/files/zh-cn/web/javascript/reference/global_objects/dataview/setint16/index.html b/files/zh-cn/web/javascript/reference/global_objects/dataview/setint16/index.html new file mode 100644 index 0000000000..92d8deb975 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/dataview/setint16/index.html @@ -0,0 +1,86 @@ +--- +title: DataView.prototype.setInt16() +slug: Web/JavaScript/Reference/Global_Objects/DataView/setInt16 +translation_of: Web/JavaScript/Reference/Global_Objects/DataView/setInt16 +--- +
{{JSRef}}
+ +

setInt16()DataView起始位置以byte为计数的指定偏移量(byteOffset)处储存一个16-bit数(短整型).

+ +
{{EmbedInteractiveExample("pages/js/dataview-setint16.html")}}
+ + + +

语法

+ +
dataview.setInt16(byteOffset, value [, littleEndian])
+ +

参数

+ +
+
byteOffset
+
偏移量,从头开始计算,单位为字节.
+
value
+
设置的数值.
+
littleEndian
+
{{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.
+
+ +

返回

+ +

{{jsxref("undefined")}}.

+ +

抛出错误

+ +
+
{{jsxref("RangeError")}}
+
如果byteOffset超出了视图能储存的值,就会抛出错误.
+
+ +

例子

+ +
var buffer = new ArrayBuffer(8);
+var dataview = new DataView(buffer);
+dataview.setInt16(1, 3);
+dataview.getInt16(1); // 3
+
+ +

规范

+ + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Typed Array')}}{{Spec2('Typed Array')}}Superseded by ECMAScript 6.
{{SpecName('ES6', '#sec-dataview.prototype.setint16', 'DataView.prototype.setInt16')}}{{Spec2('ES6')}}Initial definition in an ECMA standard.
{{SpecName('ESDraft', '#sec-dataview.prototype.setint16', 'DataView.prototype.setInt16')}}{{Spec2('ESDraft')}} 
+ +

浏览器支持

+ + + +

{{Compat("javascript.builtins.DataView.setInt16")}}

+ +

相关内容

+ + diff --git a/files/zh-cn/web/javascript/reference/global_objects/dataview/setint32/index.html b/files/zh-cn/web/javascript/reference/global_objects/dataview/setint32/index.html new file mode 100644 index 0000000000..0bbd9d2b7f --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/dataview/setint32/index.html @@ -0,0 +1,86 @@ +--- +title: DataView.prototype.setInt32() +slug: Web/JavaScript/Reference/Global_Objects/DataView/setInt32 +translation_of: Web/JavaScript/Reference/Global_Objects/DataView/setInt32 +--- +
{{JSRef}}
+ +

setInt32()DataView起始位置以byte为计数的指定偏移量(byteOffset)处储存一个32-bit数(长整型).

+ +
{{EmbedInteractiveExample("pages/js/dataview-setint32.html")}}
+ + + +

语法

+ +
dataview.setInt32(byteOffset, value [, littleEndian])
+ +

参数

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

返回

+ +

{{jsxref("undefined")}}.

+ +

抛出错误

+ +
+
{{jsxref("RangeError")}}
+
如果byteOffset超出了视图能储存的值,就会抛出错误.
+
+ +

例子

+ +
var buffer = new ArrayBuffer(8);
+var dataview = new DataView(buffer);
+dataview.setInt32(1, 3);
+dataview.getInt32(1); // 3
+
+ +

规范

+ + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Typed Array')}}{{Spec2('Typed Array')}}Superseded by ECMAScript 6.
{{SpecName('ES6', '#sec-dataview.prototype.setint32', 'DataView.prototype.setInt32')}}{{Spec2('ES6')}}Initial definition in an ECMA standard.
{{SpecName('ESDraft', '#sec-dataview.prototype.setint32', 'DataView.prototype.setInt32')}}{{Spec2('ESDraft')}} 
+ +

浏览器支持

+ + + +

{{Compat("javascript.builtins.DataView.setInt32")}}

+ +

相关

+ + 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 +--- +
{{JSRef}}
+ +

setInt8()DataView起始位置以byte为计数的指定偏移量(byteOffset)处储存一个8-bit数(一个字节).

+ +
{{EmbedInteractiveExample("pages/js/dataview-setint8.html")}}
+ + + +

语法

+ +
dataview.setInt8(byteOffset, value)
+ +

参数

+ +
+
byteOffset
+
偏移量,从头开始计算,单位为字节
+
value
+
设置的整数值
+
+

返回

+ +

{{jsxref("undefined")}}.

+
+
+ +

抛出的错误

+ +
+
{{jsxref("RangeError")}}
+
如果byteOffset超出了视图能储存的值,就会抛出错误
+
+ +

例子

+ +
var buffer = new ArrayBuffer(8);
+var dataview = new DataView(buffer);
+dataview.setInt8(1, 3);
+dataview.getInt8(1); // 3
+
+ +

规范

+ + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Typed Array')}}{{Spec2('Typed Array')}}Superseded by ECMAScript 6.
{{SpecName('ES6', '#sec-dataview.prototype.setint8', 'DataView.prototype.setInt8')}}{{Spec2('ES6')}}Initial definition in an ECMA standard.
+ +

浏览器兼容性

+ + + +

{{Compat("javascript.builtins.DataView.setInt8")}}

+ +

相关内容

+ + diff --git a/files/zh-cn/web/javascript/reference/global_objects/dataview/setuint16/index.html b/files/zh-cn/web/javascript/reference/global_objects/dataview/setuint16/index.html new file mode 100644 index 0000000000..4bcfd257e3 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/dataview/setuint16/index.html @@ -0,0 +1,86 @@ +--- +title: DataView.prototype.setUint16() +slug: Web/JavaScript/Reference/Global_Objects/DataView/setUint16 +translation_of: Web/JavaScript/Reference/Global_Objects/DataView/setUint16 +--- +
{{JSRef}}
+ +

setUint16()DataView起始位置以byte为计数的指定偏移量(byteOffset)处储存一个16-bit数(无符号短整型).

+ +
{{EmbedInteractiveExample("pages/js/dataview-setuint16.html")}}
+ + + +

语法

+ +
dataview.setUint16(byteOffset, value [, littleEndian])
+ +

参数

+ +
+
byteOffset
+
偏移量,从头开始计算,单位为字节.
+
value
+
设置的数值.
+
littleEndian
+
{{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.
+
+ +

返回

+ +

{{jsxref("undefined")}}.

+ +

抛出错误

+ +
+
{{jsxref("RangeError")}}
+
如果byteOffset超出了视图能储存的值,就会抛出错误.
+
+ +

例子

+ +
var buffer = new ArrayBuffer(8);
+var dataview = new DataView(buffer);
+dataview.setUint16(1, 3);
+dataview.getUint16(1); // 3
+
+ +

规范

+ + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Typed Array')}}{{Spec2('Typed Array')}}Superseded by ECMAScript 6.
{{SpecName('ES6', '#sec-dataview.prototype.setuint16', 'DataView.prototype.setUint16')}}{{Spec2('ES6')}}Initial definition in an ECMA standard.
{{SpecName('ESDraft', '#sec-dataview.prototype.setuint16', 'DataView.prototype.setUint16')}}{{Spec2('ESDraft')}} 
+ +

浏览器支持

+ + + +

{{Compat("javascript.builtins.DataView.setUint16")}}

+ +

相关内容

+ + diff --git a/files/zh-cn/web/javascript/reference/global_objects/dataview/setuint32/index.html b/files/zh-cn/web/javascript/reference/global_objects/dataview/setuint32/index.html new file mode 100644 index 0000000000..73857cb03c --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/dataview/setuint32/index.html @@ -0,0 +1,86 @@ +--- +title: DataView.prototype.setUint32() +slug: Web/JavaScript/Reference/Global_Objects/DataView/setUint32 +translation_of: Web/JavaScript/Reference/Global_Objects/DataView/setUint32 +--- +
{{JSRef}}
+ +

setUint32()DataView起始位置以byte为计数的指定偏移量(byteOffset)处储存一个32-bit数(无符号长整型).

+ +
{{EmbedInteractiveExample("pages/js/dataview-setuint32.html")}}
+ + + +

语法

+ +
dataview.setUint32(byteOffset, value [, littleEndian])
+ +

参数

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

返回

+ +

{{jsxref("undefined")}}.

+ +

抛出错误

+ +
+
{{jsxref("RangeError")}}
+
如果byteOffset超出了视图能储存的值,就会抛出错误.
+
+ +

例子

+ +
var buffer = new ArrayBuffer(8);
+var dataview = new DataView(buffer);
+dataview.setUint32(1, 3);
+dataview.getUint32(1); // 3
+
+ +

规范

+ + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Typed Array')}}{{Spec2('Typed Array')}}Superseded by ECMAScript 6.
{{SpecName('ES6', '#sec-dataview.prototype.setuint32', 'DataView.prototype.setUint32')}}{{Spec2('ES6')}}Initial definition in an ECMA standard.
{{SpecName('ESDraft', '#sec-dataview.prototype.setuint32', 'DataView.prototype.setUint32')}}{{Spec2('ESDraft')}} 
+ +

浏览器支持

+ + + +

{{Compat("javascript.builtins.DataView.setUint32")}}

+ +

相关内容

+ + diff --git a/files/zh-cn/web/javascript/reference/global_objects/dataview/setuint8/index.html b/files/zh-cn/web/javascript/reference/global_objects/dataview/setuint8/index.html new file mode 100644 index 0000000000..895ad521f4 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/dataview/setuint8/index.html @@ -0,0 +1,84 @@ +--- +title: DataView.prototype.setUint8() +slug: Web/JavaScript/Reference/Global_Objects/DataView/setUint8 +translation_of: Web/JavaScript/Reference/Global_Objects/DataView/setUint8 +--- +
{{JSRef}}
+ +

setUint8()DataView起始位置以byte为计数的指定偏移量(byteOffset)处储存一个8-bit数(无符号字节).

+ +
{{EmbedInteractiveExample("pages/js/dataview-setuint8.html")}}
+ + + +

语法

+ +
dataview.setUint8(byteOffset, value)
+ +

参数

+ +
+
byteOffset
+
偏移量,从头开始计算,单位为字节
+
value
+
设置的数值
+
+ +

返回

+ +

{{jsxref("undefined")}}.

+ +

抛出错误

+ +
+
{{jsxref("RangeError")}}
+
如果byteOffset超出了视图能储存的值,就会抛出错误.
+
+ +

例子

+ +
var buffer = new ArrayBuffer(8);
+var dataview = new DataView(buffer);
+dataview.setUint8(1, 3);
+dataview.getUint8(1); // 3
+
+ +

规范

+ + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Typed Array')}}{{Spec2('Typed Array')}}Superseded by ECMAScript 6.
{{SpecName('ES6', '#sec-dataview.prototype.setuint8', 'DataView.prototype.setUint8')}}{{Spec2('ES6')}}Initial definition in an ECMA standard.
{{SpecName('ESDraft', '#sec-dataview.prototype.setuint8', 'DataView.prototype.setUint8')}}{{Spec2('ESDraft')}} 
+ +

浏览器支持

+ + + +

{{Compat("javascript.builtins.DataView.setUint8")}}

+ +

相关内容

+ + -- cgit v1.2.3-54-g00ecf