| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/DataView | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 7.
* Some parts of this feature may have varying levels of support.
DataView ( )
ArrayBuffer
.
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
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 .
const buffer = new ArrayBuffer(16);
const view = new DataView(buffer, 0);
view.setInt16(1, 42);
view.getInt16(1); // 42
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-dataview-objects |
This page was last modified on 2024 2 24 by MDN contributors.
DataViewDataView.prototype.getBigInt64()DataView.prototype.getBigUint64()DataView.prototype.getFloat16()DataView.prototype.getFloat32()DataView.prototype.getFloat64()DataView.prototype.getInt8()DataView.prototype.getInt16()DataView.prototype.getInt32()DataView.prototype.getUint8()DataView.prototype.getUint16()DataView.prototype.getUint32()DataView.prototype.setBigInt64()DataView.prototype.setBigUint64()DataView.prototype.setFloat16()DataView.prototype.setFloat32()DataView.prototype.setFloat64()DataView.prototype.setInt8()DataView.prototype.setInt16()DataView.prototype.setInt32()DataView.prototype.setUint8()DataView.prototype.setUint16()DataView.prototype.setUint32()Object/FunctionObject.prototype.__defineGetter__()Object.prototype.__defineSetter__()Object.prototype.__lookupGetter__()Object.prototype.__lookupSetter__()Object.prototype.hasOwnProperty()Object.prototype.isPrototypeOf()Object.prototype.propertyIsEnumerable()Object.prototype.toLocaleString()Object.prototype.toString()Object.prototype.valueOf()Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |