DataView.prototype.byteLength
DataView 实例的 byteLength 访问器属性返回此视图的长度(以字节为单位)。
¥The byteLength accessor property of DataView instances returns the length (in bytes) of this view.
Try it
描述
¥Description
byteLength 属性是一个访问器属性,其设置的访问器函数为 undefined,这意味着你只能读取该属性。该值是在构造 DataView 时确定的,并且无法更改。如果 DataView 未指定偏移量或 byteLength,则将返回引用的 ArrayBuffer 或 SharedArrayBuffer 的 byteLength。
¥The byteLength property is an accessor property whose set accessor function is undefined, meaning that you can only read this property. The value is established when an DataView is constructed and cannot be changed. If the DataView is not specifying an offset or a byteLength, the byteLength of the referenced ArrayBuffer or SharedArrayBuffer will be returned.
示例
使用 byteLength 属性
¥Using the byteLength property
const buffer = new ArrayBuffer(8);
const dataview = new DataView(buffer);
dataview.byteLength; // 8 (matches the byteLength of the buffer)
const dataview2 = new DataView(buffer, 1, 5);
dataview2.byteLength; // 5 (as specified when constructing the DataView)
const dataview3 = new DataView(buffer, 2);
dataview3.byteLength; // 6 (due to the offset of the constructed DataView)
规范
| Specification |
|---|
| ECMAScript Language Specification # sec-get-dataview.prototype.bytelength |
浏览器兼容性
BCD tables only load in the browser
也可以看看
¥See also