SharedArrayBuffer.prototype.growable

Limited availability

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

SharedArrayBuffer 实例的 growable 访问器属性返回该 SharedArrayBuffer 是否可以增长。

¥The growable accessor property of SharedArrayBuffer instances returns whether this SharedArrayBuffer can be grow or not.

描述

¥Description

growable 属性是一个访问器属性,其设置的访问器函数为 undefined,这意味着你只能读取该属性。该值是在构造数组时确定的。如果在构造函数中设置了 maxByteLength 选项,则 growable 将返回 true;如果不是,则返回 false

¥The growable 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. If a maxByteLength option was set in the constructor, growable will return true; if not, it will return false.

示例

¥Examples

使用可生长的

¥Using growable

在此示例中,我们创建一个可增长到最大长度 16 字节的 8 字节缓冲区,然后检查其 growable 属性,如果 growable 返回 true,则增长它:

¥In this example, we create a 8-byte buffer that is growable to a max length of 16 bytes, then check its growable property, growing it if growable returns true:

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

if (buffer.growable) {
  console.log("SAB is growable!");
  buffer.grow(12);
}

规范

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

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看