Uint16Array

API

 Typ Uint16Array reprezentuje tablicę 16-bitowych liczb całkowitych bez znaku w porządku bajtów platformy. Jeśli jest potrzebna kontrola nad porządkiem bajtów, użyj DataView.

Po zdefiniowaniu, pozwala odwołać się do elementów w tablicy używając metod obiektu, lub używając standardowej tablicy ze składnią indeks (to jest, używając kwadratowych nawiasów).

Konstruktory

Note: W tych metodach, TypedArray reprezentuje każdy z typów obiektu tablic typów.
Uint16Array Uint16Array(unsigned long length);
Uint16Array Uint16Array(TypedArray array);
Uint16Array Uint16Array(sequence<type> array);
Uint16Array Uint16Array(ArrayBuffer buffer, optional unsigned long byteOffset, optional unsigned long length);

Opis metod

Note: W tych metodach, TypedArray reprezentuje każdy z typów obiektu tablic typów.
void set(TypedArray array, optional unsigned long offset);
void set(type[] array, optional unsigned long offset);
Uint16Array subarray(long begin, optional long end);

Atrybuty

Attribute Type Description
buffer ArrayBuffer Obiekt ArrayBuffer wykorzystany do zawarcia informacji z TypedArray. Tylko do odczytu.
byteOffset unsigned long The index at wich starts the TypedArray in it underlying ArrayBuffer. Tylko do odczytu.
length unsigned long Ilość wpisów w tablicy. Tylko do odczytu.

Stałe

Rozmiar elementu

Constant Value Description
BYTES_PER_ELEMENT 2 Rozmiar, w bajtach, każdego elementu tablicy.

Konstruktor

Zwraca nowy obiekt Uint16Array.

Uint16Array Uint16Array(
  unsigned long length
);

Uint16Array Uint16Array(
  TypedArray array
);

Uint16Array Uint16Array(
  sequence<type> array
);

Uint16Array Uint16Array(
  ArrayBuffer buffer,
  optional unsigned long byteOffset,
  optional unsigned long length
);
Parameters
length
Ilość elementów w tablicy z bajtami. Jeśli nieokreślona, długość widoku tablicy będzie odpowiadała długości bufora.
array
Dowolny obiekt z istniejących tablic typów (np. Int32Array), lub sekwencja obiektów konkretnego typu, do skopiowania do nowego ArrayBuffer. Każda wartość w źródłowej tablicy jest konwertowana do 16-bitowej liczby całkowitej bez znaku zanim zostanie skopiowana do nowej tablicy.
buffer
Istniejący ArrayBuffer do użycia jako magazyn dla nowego obiektu Uint16Array.
byteOffset
The offset, in bytes, to the first byte in the specified buffer for the new view to reference. If not specified, the Uint16Array's view of the buffer will start with the first byte.
Return value

A new Uint16Array object representing the specified data buffer.

Notes

The first form of the constructor, accepting only a length, creates a new ArrayBuffer object that can hold the specified number of unsigned 16-bit integers, then creates and returns a typed array view referring to that new buffer. The length must be specified in this case.

The second form creates a new ArrayBuffer object that is a duplicate of the specified array, except with each element in the new array converted to a 16-bit unsigned integer.

The third form of the constructor likewise creates a new ArrayBuffer object that is a duplicate of the specified JavaScript array, with each element in the new array converted to a 16-bit unsigned integer.

The final form of the constructor creates a new Uint16Array object, using the specified ArrayBuffer as its storage. This lets you access the existing buffer in a different format. If specified, the byteOffset and length parameters let you create the new view to only a portion of the buffer.

Exceptions thrown
INDEX_SIZE_ERR
The specified byteOffset isn't a multiple of the element size, or the byteOffset and length result in the specified view extending past the end of the buffer.

Methods

set()

Sets multiple values in the typed array, reading input values from a specified array.

void set(
  TypedArray array,
  optional unsigned long offset
);

void set(
  type[] array,
  optional unsigned long offset
);
Parameters
array
An array from which to copy values. All values from the source array are copied into the target array, unless the length of the source array plus the offset exceeds the length of the target array, in which case an exception is thrown. If the source array is a typed array, the two arrays may share the same underlying ArrayBuffer; the browser will intelligently copy the source range of the buffer to the destination range.
offset Optional
The offset into the target array at which to begin writing values from the source array. If you omit this value, 0 is assumed (that is, the source array will overwrite values in the target array starting at index 0).

subarray()

Returns a new Uint16Array view on the ArrayBuffer store for this Uint16Array object.

Uint16Array subarray(
  long begin,
  optional long end
);
Parameters
begin
The offset of the first element in the array to be referenced by the new Uint16Array object.
end Optional
The offset of the element one-past the last element to be referenced by the new Uint16Array object; if not specified, all elements from the one specified by begin to the end of the array are included in the new view.
Notes

The range specified by begin and end is clamped to the valid index range for the current array; if the computed length of the new array would be negative, it's clamped to zero. If either begin or end is negative, it refers to an index from the end of the array instead of from the beginning.

Uwaga: Pamiętaj, że to tworzy nowy widok istniejącego bufora; zmiany w zawartości nowego obiektu wpłyną na oryginalny obiekt i odwrotnie.

Zobacz także

Document Tags and Contributors

Contributors to this page: Kuzirashi
Ostatnia aktualizacja: Kuzirashi,