2.9.1.2.4.3 TypeArray.prototype.subarray(begin [, end] )

Returns a new TypedArray view of the ArrayBuffer store for this TypedArray, referencing the elements at begin, inclusive, up to end, exclusive. If either begin or end is negative, it refers to an index from the end of the array, as opposed to from the beginning.

  1. If this does not have class "TypeArray", throw a TypeError.

  2. Let srcLength be the result of calling [[Get]] on this with property name "length"

  3. Let beginInt be ToInt32(begin)

  4. If beginInt < 0, let beginInt be srcLength + beginInt

  5. Let beginIndex be min(srcLength, max(0, beginInt))

  6. Let endInt be ToInt32(end) if end was provided, else srcLength.

  7. If endInt <0,let endInt be srcLength + endInt

  8. Let endIndex be max(0,min(srcLength, endInt))

  9. If endIndex < beginIndex, let endIndex be beginIndex

  10. Return a new TypeArray with the following values for it’s proeprties:

    1. The length property of the newly constructed object is set to endIndex - beginIndex

    2. The byteLength property of the newly constructed object is set to length multiplied by the size in bytes of Type.

    3. The buffer property of the newly constructed object is set to this.buffer.

    4. The byteOffset property of the newly constructed object is set to this.offset + beginIndex.