大网数据广告活动
Web 标准与前端开发

ArrayBuffer.prototype.maxByteLength

· 52CE 我爱测

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

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

JavaScript Demo: ArrayBuffer.maxByteLength

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

console.log(buffer.byteLength);
// Expected output: 8

console.log(buffer.maxByteLength);
// Expected output: 16

描述

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

如果该 ArrayBuffer 已分离,则该属性返回 0。如果该 ArrayBuffer 构造时未指定 maxByteLength 值,则该属性返回 ArrayBuffer 的 ArrayBuffer/byteLength 值。

示例

使用 maxByteLength

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

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

buffer.maxByteLength; // 16

规范

浏览器兼容性

参见

  • ArrayBuffer
  • ArrayBuffer.prototype.byteLength
  • ArrayBuffer.prototype.resize()

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。