DataView
Baseline
Widely available
*
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since â¨2015ë 7ìâ©.
* Some parts of this feature may have varying levels of support.
DataView ë·°ë íë«í¼ì ìì²´ ìëì¸(ë°ì´í¸ ì ë ¬ ë°©ë²)ì
ì ê²½ì°ì§ ìì¼ë©´ì ArrayBufferìì ë¤ìí ì«ì ìë£íì ë°ì´í°ë¥¼ ì½ê³ ì°ê¸° ìí
ì ìì¤ ì¸í°íì´ì¤ë¥¼ ì ê³µí©ëë¤.
ì¤ëª
>ìëì¸
ë¤ì¤ ë°ì´í¸ ì«ì ìë£íì ì¥ì¹ì ìí¤í
ì²ì ë°ë¼ ë©ëª¨ë¦¬ì ë¤ë¥´ê² ííë©ëë¤. ìëì¸
ì©ì´ ì¬ì ì ì°¸ê³ íì¸ì. DataView ì ê·¼ìë ì½ë를 ì¤ííë ì»´í¨í°ì ìëì¸ì ê´ê³ ìì´ ë°ì´í°ì ì ê·¼ë²ì
ëª
ìì ì¼ë¡ íµì í ì ììµëë¤.
const littleEndian = (() => {
const buffer = new ArrayBuffer(2);
new DataView(buffer).setInt16(0, 256, true /* littleEndian */);
// Int16Array uses the platform's endianness.
return new Int16Array(buffer)[0] === 256;
})();
console.log(littleEndian); // true or false
64ë¹í¸ ì ì ìë£í
JavaScriptë 64ë¹í¸ ì ìí ê°ì ëí íì¤ ì§ìì ìì§ ì ê³µíì§ ìì¼ë¯ë¡ DataViewë 64ë¹í¸ ì°ì°ì ì§ìíì§ ììµëë¤.
íìí ê²½ì° ìµë ì íë Number.MAX_SAFE_INTEGERì ê°ì ê°ì ¸ì¬ ì ìë getUint64()
í¨ì를 ë§ë¤ ìë ìì¼ë©°, ì´ë ì ëê¹ì§ë ì¶©ë¶í ê²ì
ëë¤.
function getUint64(dataview, byteOffset, littleEndian) {
// split 64-bit number into two 32-bit (4-byte) parts
const left = dataview.getUint32(byteOffset, littleEndian);
const right = dataview.getUint32(byteOffset + 4, littleEndian);
// combine the two 32-bit values
const combined = littleEndian
? left + 2 ** 32 * right
: 2 ** 32 * left + right;
if (!Number.isSafeInteger(combined))
console.warn(combined, "exceeds MAX_SAFE_INTEGER. Precision may be lost");
return combined;
}
ìì í ë²ìì 64ë¹í¸ë¥¼ ì§ìí´ì¼ í ê²½ì° BigInt를 ì¬ì©íì¸ì.
ë¨, BigIntë ì¬ì©ì ê³ì¸µ ë¼ì´ë¸ë¬ë¦¬ 구íì²´ë³´ë¤ë í¨ì¬ ë¹ ë¥´ì§ë§, ê°ë³ í¬ê¸°ë¼ë ì±ì§ë¡ ì¸í´ JavaScript 32ë¹í¸ ì ìë³´ë¤ë
íì ë릴 ìë°ì ììµëë¤.
const BigInt = window.BigInt,
bigThirtyTwo = BigInt(32),
bigZero = BigInt(0);
function getUint64BigInt(dataview, byteOffset, littleEndian) {
// split 64-bit number into two 32-bit (4-byte) parts
const left = BigInt(dataview.getUint32(byteOffset | 0, !!littleEndian) >>> 0);
const right = BigInt(
dataview.getUint32(((byteOffset | 0) + 4) | 0, !!littleEndian) >>> 0,
);
// combine the two 32-bit values and return
return littleEndian
? (right << bigThirtyTwo) | left
: (left << bigThirtyTwo) | right;
}
ìì±ì
DataView()-
ìë¡ì´
DataViewê°ì²´ë¥¼ ìì±í©ëë¤.
ì¸ì¤í´ì¤ ìì±
ì´ ìì±ì DataView.prototypeì ì ìëì´ ìì¼ë©° 모ë DataView ì¸ì¤í´ì¤ì ê³µì ë©ëë¤.
DataView.prototype.buffer-
ì´ ë·°ê° ì°¸ì¡°íë
ArrayBufferì ëë¤. ìì± ìê°ì ê°ì´ ì í´ì§ê¸°ì ì½ê¸° ì ì©ì ëë¤. DataView.prototype.byteLength-
ì´ ë·°ì 길ì´(ë°ì´í¸ ë¨ì)ì ëë¤. ìì± ìê°ì ê°ì´ ì í´ì§ê¸°ì ì½ê¸° ì ì©ì ëë¤.
DataView.prototype.byteOffset-
ì´ ë·°ì
ArrayBufferì ììì ë¶í°ì ì¤íì (ë°ì´í¸ ë¨ì)ì ëë¤. ìì± ìê°ì ê°ì´ ì í´ì§ê¸°ì ì½ê¸° ì ì©ì ëë¤. DataView.prototype.constructor-
ì¸ì¤í´ì¤ ê°ì²´ë¥¼ ìì±í ìì±ì í¨ìì ëë¤.
DataViewì¸ì¤í´ì¤ì ê²½ì° ì´ê¸° ê°ìDataViewìì±ìì ëë¤. DataView.prototype[@@toStringTag]-
@@toStringTagìì±ì ì´ê¸° ê°ì 문ìì´"DataView"ì ëë¤. ì´ ìì±ìObject.prototype.toString()ìì ì¬ì©ë©ëë¤.
ì¸ì¤í´ì¤ ë©ìë
DataView.prototype.getBigInt64()-
ì´
DataViewì í¹ì ë°ì´í¸ ì¤íì ììë¶í° 8ë°ì´í¸ë¥¼ ì½ì´ìì 64ë¹í¸ ë¶í¸ ìë ì ìë¡ í´ìí©ëë¤. DataView.prototype.getBigUint64()-
ì´
DataViewì í¹ì ë°ì´í¸ ì¤íì ììë¶í° 8ë°ì´í¸ë¥¼ ì½ì´ìì 64ë¹í¸ ë¶í¸ ìë ì ìë¡ í´ìí©ëë¤. DataView.prototype.getFloat32()-
ì´
DataViewì í¹ì ë°ì´í¸ ì¤íì ììë¶í° 4ë°ì´í¸ë¥¼ ì½ì´ìì 32ë¹í¸ ì¤ìë¡ í´ìí©ëë¤. DataView.prototype.getFloat64()-
ì´
DataViewì í¹ì ë°ì´í¸ ì¤íì ììë¶í° 8ë°ì´í¸ë¥¼ ì½ì´ìì 64ë¹í¸ ì¤ìë¡ í´ìí©ëë¤. DataView.prototype.getInt16()-
ì´
DataViewì í¹ì ë°ì´í¸ ì¤íì ììë¶í° 2ë°ì´í¸ë¥¼ ì½ì´ìì 16ë¹í¸ ë¶í¸ ìë ì ìë¡ í´ìí©ëë¤. DataView.prototype.getInt32()-
ì´
DataViewì í¹ì ë°ì´í¸ ì¤íì ììë¶í° 4ë°ì´í¸ë¥¼ ì½ì´ìì 32ë¹í¸ ë¶í¸ ìë ì ìë¡ í´ìí©ëë¤. DataView.prototype.getInt8()-
ì´
DataViewì í¹ì ë°ì´í¸ ì¤íì ììë¶í° 1ë°ì´í¸ë¥¼ ì½ì´ìì 8ë¹í¸ ë¶í¸ ìë ì ìë¡ í´ìí©ëë¤. DataView.prototype.getUint16()-
ì´
DataViewì í¹ì ë°ì´í¸ ì¤íì ììë¶í° 2ë°ì´í¸ë¥¼ ì½ì´ìì 16ë¹í¸ ë¶í¸ ìë ì ìë¡ í´ìí©ëë¤. DataView.prototype.getUint32()-
ì´
DataViewì í¹ì ë°ì´í¸ ì¤íì ììë¶í° 4ë°ì´í¸ë¥¼ ì½ì´ìì 32ë¹í¸ ë¶í¸ ìë ì ìë¡ í´ìí©ëë¤. DataView.prototype.getUint8()-
ì´
DataViewì í¹ì ë°ì´í¸ ì¤íì ììë¶í° 1ë°ì´í¸ë¥¼ ì½ì´ìì 8ë¹í¸ ë¶í¸ ìë ì ìë¡ í´ìí©ëë¤. DataView.prototype.setBigInt64()-
BigInt를 ë°ì ì´
DataViewì ì§ì ë ë°ì´í¸ ì¤íì ìì ììíì¬ 8ë°ì´í¸ì ê³µê°ì 64ë¹í¸ ë¶í¸ ìë ì ìë¡ ì ì¥í©ëë¤. DataView.prototype.setBigUint64()-
BigInt를 ë°ì ì´
DataViewì ì§ì ë ë°ì´í¸ ì¤íì ìì ììíì¬ 8ë°ì´í¸ì ê³µê°ì 64ë¹í¸ ë¶í¸ ìë ì ìë¡ ì ì¥í©ëë¤. DataView.prototype.setFloat32()-
ì«ì를 ë°ì ì´
DataViewì ì§ì ë ë°ì´í¸ ì¤íì ìì ììíì¬ 4ë°ì´í¸ì ê³µê°ì 32ë¹í¸ ì¤ìë¡ ì ì¥í©ëë¤. DataView.prototype.setFloat64()-
ì«ì를 ë°ì ì´
DataViewì ì§ì ë ë°ì´í¸ ì¤íì ìì ììíì¬ 8ë°ì´í¸ì ê³µê°ì 64ë¹í¸ ì¤ìë¡ ì ì¥í©ëë¤. DataView.prototype.setInt16()-
ì«ì를 ë°ì ì´
DataViewì ì§ì ë ë°ì´í¸ ì¤íì ìì ììíì¬ 2ë°ì´í¸ì ê³µê°ì 16ë¹í¸ ë¶í¸ ìë ì ìë¡ ì ì¥í©ëë¤. DataView.prototype.setInt32()-
ì«ì를 ë°ì ì´
DataViewì ì§ì ë ë°ì´í¸ ì¤íì ìì ììíì¬ 4ë°ì´í¸ì ê³µê°ì 32ë¹í¸ ë¶í¸ ìë ì ìë¡ ì ì¥í©ëë¤. DataView.prototype.setInt8()-
ì«ì를 ë°ì ì´
DataViewì ì§ì ë ë°ì´í¸ ì¤íì ìì ììíì¬ 1ë°ì´í¸ì ê³µê°ì 8ë¹í¸ ë¶í¸ ìë ì ìë¡ ì ì¥í©ëë¤. DataView.prototype.setUint16()-
ì«ì를 ë°ì ì´
DataViewì ì§ì ë ë°ì´í¸ ì¤íì ìì ììíì¬ 2ë°ì´í¸ì ê³µê°ì 16ë¹í¸ ë¶í¸ ìë ì ìë¡ ì ì¥í©ëë¤. DataView.prototype.setUint32()-
ì«ì를 ë°ì ì´
DataViewì ì§ì ë ë°ì´í¸ ì¤íì ìì ììíì¬ 4ë°ì´í¸ì ê³µê°ì 32ë¹í¸ ë¶í¸ ìë ì ìë¡ ì ì¥í©ëë¤. DataView.prototype.setUint8()-
ì«ì를 ë°ì ì´
DataViewì ì§ì ë ë°ì´í¸ ì¤íì ìì ììíì¬ 1ë°ì´í¸ì ê³µê°ì 8ë¹í¸ ë¶í¸ ìë ì ìë¡ ì ì¥í©ëë¤.
ìì
>DataView ì¬ì©í기
const buffer = new ArrayBuffer(16);
const view = new DataView(buffer, 0);
view.setInt16(1, 42);
view.getInt16(1); // 42
ëª ì¸ì
| Specification |
|---|
| ECMAScript® 2026 Language Specification > # sec-dataview-objects > |