Variable CallableObjectConst

CallableObject: (new <T extends AnyFunction>(fn: T) => T) = ...

A base class for creating callable objects.

The way this works is that you subclass CallableObject and define a constructor that calls super(someClosure) where someClosure is a unique function object, which will then pick up any properties or methods defined by the subclass.

(Note: It needs to be unique because the super() call only sets its prototype, and returns the function you passed as this. So if you call it with the same function more than once, you're just reinitializing the same object instead of creating a new one.)

Type declaration

    • new <T extends AnyFunction>(fn: T): T
    • Type Parameters

      • T extends AnyFunction

        The call/return signature that instances of the class will implement.

      Parameters

      • fn: T

        A unique function or closure, to be passed to super() in a subclass. The function object will gain a prototype from new.target, thereby picking up any properties or methods defined by the class, and becoming this for the calling constructor.

        (Note that calling the constructor by any means other than super() from a constructor will result in an error or some other unhelpful result.)

      Returns T