DataView.prototype.getInt16()

getInt16()方法DataView相对于起始位置偏移 n 个字节处开始,获取一个16-bit数(短整型,2个字节).

语法

dataview.getInt16(byteOffset [, littleEndian])

参数

byteOffset
偏移量, 单位为字节, 从头开始计算.
littleEndian
可选 表示该 16 位整数是否以 little- or big-endian 格式存储的(就是使用的字节序格式,具体参考链接页面);如果传入的值为 true,就表示使用 little-endian(低字节序),如果传入的值为 false 或者 undefined,则会使用 big-endian(高字节序) 方式读值。

返回

一个短整型16位数.

抛出错误

RangeError
如果byteOffset超出了视图能储存的值,就会抛出错误.

描述

 没有对齐约束; 多字节值可以从任何偏移量获取.

例子

var buffer = new ArrayBuffer(8);
var dataview = new DataView(buffer);
dataview.getInt16(1); // 0

规范

Specification Status Comment
Typed Array Specification Obsolete Superseded by ECMAScript 6.
ECMAScript 2015 (6th Edition, ECMA-262)
DataView.prototype.getInt16
Standard Initial definition in an ECMA standard.
ECMAScript (ECMA-262)
DataView.prototype.getInt16
Living Standard

浏览器支持

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
getInt16Chrome Full support 9Edge Full support 12Firefox Full support 15IE Full support 10Opera Full support 12.1Safari Full support 5.1WebView Android Full support 4Chrome Android Full support 18Firefox Android Full support 15Opera Android Full support 12.1Safari iOS Full support 4.2Samsung Internet Android Full support 1.0nodejs Full support 0.10

Legend

Full support  
Full support

另见