Array.prototype.slice.call()-like method for TypedArrays, Buffers and Arguments
A poly fill for
slice that uniformly and efficiently implements
Array-like semantics for the following classses of objects:
npm install generic-slice
var slice =var x = 4x0 = 1x1 = 2x2 = 3x3 = 4var y =// Now:// y = [ 1, 2 ]// x = [ 1, 2, 3, 4 ]y0 = 1000// Now:// y = [ 1000, 2 ]// x = [ 1, 2, 3, 4 ]
A generic polyfill for slicing array-like objects.
arrayis a typed array, buffer, Array, or Arguments object
sliceBeginis an optional argument giving the start of the slice. Negative values change counting to end of array. (Default: 0)
sliceEndis an optional argument giving the end of the slice. Negative values wrap around. (Default: array.length)
Returns A copy of the array from the range
slicegot dropped from the typed array specification (and the replacement method,
.subarray()merely returns a view and does not make a copy)
Buffer's slice method does not make a copy like Array's slice does, and so it has inconsistent semantics.
Argumentsdoesn't have a slice method either
Array.prototype.slice.calldoesn't properly preserve the types of things like Buffers or typed arrays
Array.prototype.slice.callcan be slower than an appropriate implementation. For example, to clone a typed array you can slice the underlying ArrayBuffer assuming that you are careful about how you perform indexing.
All of the major edge cases should be tested. If you find a bug, please open an issue or send a pull request.
(c) 2013 Mikola Lysenko. MIT License