ArrayBuffer.prototype.maxByteLength

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

ArrayBuffer 实例的 maxByteLength 访问器属性返回此数组缓冲区可以调整大小的最大长度(以字节为单位)。

¥The maxByteLength accessor property of ArrayBuffer instances returns the maximum length (in bytes) that this array buffer can be resized to.

Try it

描述

¥Description

maxByteLength 属性是一个访问器属性,其设置的访问器函数为 undefined,这意味着你只能读取该属性。该值在构造数组时确定,通过 ArrayBuffer() 构造函数的 maxByteLength 选项设置,并且无法更改。

¥The maxByteLength property is an accessor property whose set accessor function is undefined, meaning that you can only read this property. The value is established when the array is constructed, set via the maxByteLength option of the ArrayBuffer() constructor, and cannot be changed.

如果此 ArrayBuffer 已分离,则此属性返回 0。如果构造此 ArrayBuffer 时未指定 maxByteLength 值,则此属性返回的值等于 ArrayBufferbyteLength 的值。

¥This property returns 0 if this ArrayBuffer has been detached. If this ArrayBuffer was constructed without specifying a maxByteLength value, this property returns a value equal to the value of the ArrayBuffer's byteLength.

示例

¥Examples

使用最大字节长度

¥Using maxByteLength

在此示例中,我们创建一个 8 字节缓冲区,最大长度可调整为 16 字节,然后返回其 maxByteLength

¥In this example, we create an 8-byte buffer that is resizable to a max length of 16 bytes, then return its maxByteLength:

js
const buffer = new ArrayBuffer(8, { maxByteLength: 16 });

buffer.maxByteLength; // 16

规范

Specification
ECMAScript Language Specification
# sec-get-arraybuffer.prototype.maxbytelength

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看