ArrayBuffer.prototype.transferToFixedLength()
Baseline
2024
Newly available
Since โจMarch 2024โฉ, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
ArrayBuffer
์ธ์คํด์ค์ transferToFixedLength()
๋ฉ์๋๋ ์ด ๋ฒํผ์ ๋ด์ฉ๊ณผ ๋์ผํ ๋ฐ์ดํธ์ ํฌ๊ธฐ ์กฐ์ ์ด ๋ถ๊ฐ๋ฅํ ArrayBuffer
๋ฅผ ์๋ก ์์ฑํ๊ณ ์ด ๋ฒํผ๋ฅผ ๋ถ๋ฆฌํฉ๋๋ค.
๊ตฌ๋ฌธ
transferToFixedLength()
transferToFixedLength(newByteLength)
๋งค๊ฐ๋ณ์
newByteLength
-
์
ArrayBuffer
์byteLength
์ ๋๋ค. ๊ธฐ๋ณธ๊ฐ์ ์ดArrayBuffer
์byteLength
์ ๋๋ค.newByteLength
๊ฐ ์ดArrayBuffer
์byteLength
๋ณด๋ค ์์ผ๋ฉด ํด๋น ๋ฒํผ์ ๋ด์ง๋ชปํด ๋์น๋ ๋ฐ์ดํธ๋ ์ญ์ ๋ฉ๋๋ค.newByteLength
๊ฐ ์ดArrayBuffer
์byteLength
๋ณด๋ค ํฌ๋ค๋ฉด ๋จ๋ ๋ฐ์ดํธ๋ 0์ผ๋ก ์ฑ์์ง๋๋ค.
๋ฐํ ๊ฐ
์๋ก์ด ArrayBuffer
๊ฐ์ฒด. ํด๋น ๊ฐ์ฒด์ ๋ด์ฉ์ ์ด ArrayBuffer
์ ๋ด์ฉ์ผ๋ก ์ด๊ธฐํ๋๋ฉฐ, ์ฌ๋ถ์ ๋ฐ์ดํธ๊ฐ ์๋ค๋ฉด 0์ผ๋ก ์ฑ์์ง๋๋ค. ์๋ก์ด ArrayBuffer
๋ ์ธ์ ๋ ํฌ๊ธฐ ์กฐ์ ์ด ๋ถ๊ฐ๋ฅํฉ๋๋ค. ์๋ณธ ArrayBuffer
๋ ๋ถ๋ฆฌ๋ฉ๋๋ค.
์์ธ
TypeError
-
์ด
ArrayBuffer
๊ฐ ์ด๋ฏธ ๋ถ๋ฆฌ๋์๋ค๋ฉด ๋ฐ์ํฉ๋๋ค.
์ค๋ช
transfer()
์ ๋ฌ๋ฆฌ, transferToFixedLength()
๋ ํญ์ ํฌ๊ธฐ ์กฐ์ ์ด ๋ถ๊ฐ๋ฅํ ArrayBuffer
๋ฅผ ์์ฑํฉ๋๋ค. ์ฆ, ์ด ArrayBuffer
๊ฐ ํฌ๊ธฐ ์กฐ์ ์ด ๊ฐ๋ฅํ๋๋ผ๋ newByteLength
๊ฐ maxByteLength
๋ณด๋ค ํด ์ ์์ต๋๋ค. ์์ธํ ๋ด์ฉ์ ArrayBuffer ์ ์กํ๊ธฐ๋ฅผ ์ฐธ์กฐํ์ธ์.
์์
๊ณ ์ ๊ธธ์ด ๋ฒํผ์ ํฌ๊ธฐ ์กฐ์ ๊ฐ๋ฅํ ArrayBuffer ์ ์กํ๊ธฐ
const buffer = new ArrayBuffer(8, { maxByteLength: 16 });
const view = new Uint8Array(buffer);
view[1] = 2;
view[7] = 4;
const buffer2 = buffer.transferToFixedLength();
console.log(buffer2.byteLength); // 8
console.log(buffer2.resizable); // false
const view2 = new Uint8Array(buffer2);
console.log(view2[1]); // 2
console.log(view2[7]); // 4
transferToFixedLength
๋ฅผ ์ฌ์ฉํ๋ฉด newByteLength
๋ ์๋ณธ ArrayBuffer
์ maxByteLength
๋ณด๋ค ํด ์ ์์ต๋๋ค.
const buffer = new ArrayBuffer(8, { maxByteLength: 16 });
const view = new Uint8Array(buffer);
view[1] = 2;
view[7] = 4;
const buffer2 = buffer.transferToFixedLength(20);
console.log(buffer2.byteLength); // 20
console.log(buffer2.resizable); // false
const view2 = new Uint8Array(buffer2);
console.log(view2[1]); // 2
console.log(view2[7]); // 4
๋ช ์ธ์
Specification |
---|
ECMAScriptยฎ 2026 Language Specification # sec-arraybuffer.prototype.transfertofixedlength |
๋ธ๋ผ์ฐ์ ํธํ์ฑ
Loadingโฆ