Skip to content

Instantly share code, notes, and snippets.

@kawasako
Created May 30, 2016 08:13
Show Gist options
  • Save kawasako/f799539c85265fe5a15e8f09a6080d68 to your computer and use it in GitHub Desktop.
Save kawasako/f799539c85265fe5a15e8f09a6080d68 to your computer and use it in GitHub Desktop.
PooledClassの実装
export default class PooledClass {
constructor(clazz) {
this.clazz = clazz;
this.pool = [];
}
alloc(...args) {
let instance = this.pool.pop();
if (!instance) {
instance = new this.clazz();
}
instance.init(...args);
}
dealloc(instance) {
this.pool.push(instance);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment