Function Poolable

  • オブジェクトプーリング機能を付与する

    Example

    class Actor extends Poolable(class {}) {
    name: string = "";
    remove() { this.isPoolPickable = true }
    resetParam() {
    this.name = "John Doe"
    this.isPoolPickable = false
    }
    declare static pick: () => Actor;
    }

    // Newly created
    const actor = Actor.pick();
    actor.name = "pentamania";

    // Back to pool
    actor.remove()

    // Picked from pool, not newly created
    const actor2 = Actor.pick();

    // Should be reset
    console.log(actor2.name); // "John Doe"

    Type Parameters

    Parameters

    • Base: TBase

    Returns {
        prototype: __type<any>;
        get pooledNum(): number;
        checkAvailable(obj: any): boolean;
        clearPool(): void;
        createInstance(): __type<TBase>;
        pick(..._args: any): __type<TBase>;
        pool(): void;
        new (...args: any[]): __type<TBase>;
    } & TBase

Generated using TypeDoc