OPool
Simple & super fast object pool for javascript
Usage
To create a new pool you just need to provide a constructor function to the exported class.
You constructor function must have a prototype function called reset
, which will be called upon release.
To get a new object, just call pool.get()
. To add an object to the pool call pool.release(obj);
.
Typescript
; ; // Then somewhere else... ; // returns new MyClass; // returns new MyClass pool.releaseobj1; // reset() is automatically called here ; // obj3 is now identical to obj1
Javascript (ES5)
var Pool = ; { MyClass;}MyClass { objsomething = null;} var pool = MyClass; // Then somewhere deep down... { var obj = pool; objsomething = 'test'; pool; // You should stop using `obj` now // obj.reset is automatically called here}; { var obj2 = pool; // This is actually the same as `obj` above. console; // > null obj2something = 'test'; pool;};