58 lines
1.3 KiB
Plaintext
58 lines
1.3 KiB
Plaintext
|
|
||
|
{{alias}}( buffer )
|
||
|
Circular buffer constructor.
|
||
|
|
||
|
Parameters
|
||
|
----------
|
||
|
buffer: integer|ArrayLike
|
||
|
Buffer size or an array-like object to use as the underlying buffer.
|
||
|
|
||
|
Returns
|
||
|
-------
|
||
|
buf: Object
|
||
|
Circular buffer data structure.
|
||
|
|
||
|
buf.clear: Function
|
||
|
Clears the buffer.
|
||
|
|
||
|
buf.count: integer
|
||
|
Number of elements currently in the buffer.
|
||
|
|
||
|
buf.full: boolean
|
||
|
Boolean indicating whether the buffer is full.
|
||
|
|
||
|
buf.iterator: Function
|
||
|
Returns an iterator for iterating over a buffer. If an environment
|
||
|
supports Symbol.iterator, the returned iterator is iterable. Note that a
|
||
|
returned iterator does **not** iterate over partially full buffers.
|
||
|
|
||
|
buf.length: integer
|
||
|
Buffer length (capacity).
|
||
|
|
||
|
buf.push: Function
|
||
|
Adds a value to the buffer. If the buffer is full, the method returns
|
||
|
the removed value; otherwise, the method returns `undefined`.
|
||
|
|
||
|
buf.toArray: Function
|
||
|
Returns an array of buffer values.
|
||
|
|
||
|
buf.toJSON: Function
|
||
|
Serializes a circular buffer as JSON.
|
||
|
|
||
|
Examples
|
||
|
--------
|
||
|
> var b = {{alias}}( 3 );
|
||
|
> b.push( 'foo' );
|
||
|
> b.push( 'bar' );
|
||
|
> b.push( 'beep' );
|
||
|
> b.length
|
||
|
3
|
||
|
> b.count
|
||
|
3
|
||
|
> b.push( 'boop' )
|
||
|
'foo'
|
||
|
|
||
|
See Also
|
||
|
--------
|
||
|
|