ObjectInstance.ts 473 Bytes
import ObjectPool from "./ObjectPool";

/*
* name;
*/
export default class ObjectInstance {
    private static clzs = [];
    private static objects = [];

    public static get(cls: any) {
        let idx = this.clzs.indexOf(cls);
        return (idx >= 0 && this.objects[idx]) || this.create(cls);
    }

    private static create(cls: any) {
        var obj = ObjectPool.pop(cls);
        this.objects.push(obj);
        this.clzs.push(cls);
        return obj;
    }

}