Created
May 30, 2016 08:13
-
-
Save kawasako/f799539c85265fe5a15e8f09a6080d68 to your computer and use it in GitHub Desktop.
PooledClassの実装
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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