ArrayBuffer.prototype.resizable

Limited availability

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

ArrayBuffer 实例的 resizable 访问器属性返回该数组缓冲区是否可以调整大小。

¥The resizable accessor property of ArrayBuffer instances returns whether this array buffer can be resized or not.

Try it

描述

¥Description

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

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

示例

¥Examples

使用可调整大小

¥Using resizable

在此示例中,我们创建一个 8 字节缓冲区,最大长度可调整为 16 字节,然后检查其 resizable 属性,如果 resizable 返回 true 则调整其大小:

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

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

if (buffer.resizable) {
  console.log("Buffer is resizable!");
  buffer.resize(12);
}

规范

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

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看