跳至主要內容

ArrayBuffer.prototype.transfer 和相关的

小于 1 分钟featurees-proposal

ArrayBuffer.prototype.transfer 和相关的open in new window

ArrayBuffer.prototype.{ transfer, transferToFixedLength } 只在原生支持 ArrayBufferstructuredClone 转换运行时中被 polyfill。

模块

类型

interface ArrayBuffer {
  get detached(): boolean;
  transfer(newLength?: number): ArrayBuffer;
  transferToFixedLength(newLength?: number): ArrayBuffer;
}

入口点

core-js/proposals/array-buffer-transfer
core-js/actual|full/array-buffer
core-js/actual|full/array-buffer/detached
core-js/actual|full/array-buffer/transfer
core-js/actual|full/array-buffer/transfer-to-fixed-length

示例

示例open in new window:

const buffer = Int8Array.of(1, 2, 3, 4, 5, 6, 7, 8).buffer;
console.log(buffer.byteLength); // => 8
console.log(buffer.detached); // => false
const newBuffer = buffer.transfer(4);
console.log(buffer.byteLength); // => 0
console.log(buffer.detached); // => true
console.log(newBuffer.byteLength); // => 4
console.log(newBuffer.detached); // => false
console.log([...new Int8Array(newBuffer)]); // => [1, 2, 3, 4]