The TypedArray specification states that an ArrayBufferView may be created this way:
TypedArray(ArrayBuffer buffer,
optional unsigned long byteOffset, optional unsigned long length)
However, the second parameter, byteOffset
, has a limitation:
The given byteOffset must be a multiple of the element size of the specific type, otherwise an exception is raised.
This means we cannot work with odd offsets for two-byte views, such as:
var view1 = new Uint8Array([0, 1, 2, 3]),
view2 = new Uint16Array(view1.buffer, 1, 1);
So, even though [1,2] could be correctly converted into Uint16, I can't access those elements that way.
The byteOffset limitation seems to significantly decrease ArrayBufferView
's flexibility.
Does anybody know why this limitation was imposed?