此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

SharedArrayBuffer.prototype.maxByteLength

基线 2024
最近可用

自 July 2024 起,此特性已在最新浏览器中得到支持。但在较旧的设备或浏览器中可能无法运行。

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

描述

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

如果当前 SharedArrayBuffer 构造时时没有指定 maxByteLength 的值,这个属性会返回一个等于 SharedArrayBufferbyteLength 属性值的数值。

示例

使用 maxByteLength

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

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

buffer.maxByteLength; // 16

规范

规范
ECMAScript® 2027 Language Specification
# sec-get-sharedarraybuffer.prototype.maxbytelength

浏览器兼容性

参见