SharedArrayBuffer.prototype.maxByteLength

Limited availability

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

SharedArrayBuffer 实例的 maxByteLength 访问器属性返回此 SharedArrayBuffer 可以增长到的最大长度(以字节为单位)。

¥The maxByteLength accessor property of SharedArrayBuffer instances returns the maximum length (in bytes) that this SharedArrayBuffer can be grown to.

描述

¥Description

maxByteLength 属性是一个访问器属性,其设置的访问器函数为 undefined,这意味着你只能读取该属性。该值是在构造共享数组时确定的,通过 SharedArrayBuffer() 构造函数的 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 shared array is constructed, set via the maxByteLength option of the SharedArrayBuffer() constructor, and cannot be changed.

如果构造此 SharedArrayBuffer 时未指定 maxByteLength 值,则此属性返回的值等于 SharedArrayBufferbyteLength 的值。

¥If this SharedArrayBuffer was constructed without specifying a maxByteLength value, this property returns a value equal to the value of the SharedArrayBuffer's byteLength.

示例

¥Examples

使用最大字节长度

¥Using maxByteLength

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

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

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

buffer.maxByteLength; // 16

规范

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

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看

¥See also