Simple JavaScript Object Pool

I needed to create a limited amount of objects, reuse them and queue up subsequent calls when the pool was full.

Usage is simple.

Create an array of object instances that you'll reuse and pass them to the Pool constructor.

Enqueue an action by passing a function to the Pool.act method. That function is pass an instance of the next available object and the Pool instance that it belongs to. When you're done with the object, put it back with Pool.add so that the next guy in line could use it

[1] http://jsfiddle.net/XkTPJ/ Red takes the longest and you'd see it used the fewest times, you should see blue 2 times more than green

This post does not have any comments yet