ArrayBuffer.prototype.transfer 和相关的
小于 1 分钟
ArrayBuffer.prototype.transfer
和相关的
注
ArrayBuffer.prototype.{ transfer, transferToFixedLength }
只在原生支持 ArrayBuffer
的 structuredClone
转换运行时中被 polyfill。
模块
esnext.array-buffer.detached
esnext.array-buffer.transfer
esnext.array-buffer.transfer-to-fixed-length
类型
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
示例
示例:
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]