All of the implementations of queues I found attached everything to the
prototype and didn't make good of private encapsulation, getters,
non-enumerable methods, etc.
This queue does not use Array#shift internally, so it keeps O(1) rather than O(n).
So here it is, a clean implementation of a queue written in straight simple es5.
Create a queue
var createQueue = ;var queue = ; // => Creates an empty queuevar queue = ; // => Creates a queue with initial values
size property works exactly the same as
length on Array.
var queue = ;queuesize // => 3
A property containing the first item in the queue.
var queue = ;queuefirst // => 'hat'
Add a new item to the queue. Returns the queue for chaining.
var queue = ;queue;queue;// queue is => ['hat', 'tree', 'house']
Gets the next item in the queue.
var queue = ;queue // => 'hat'// queue is => ['tree', 'golf']
Get the current queue as a string.
var queue = ;queue // => "1,2,3"
Copy the current queue into a regular array.
var queue = ;queue // => [1, 2, 3]