• Get a string name for a class method.

    Time complexity: O(1)

    Space complexity: O(1)

    Parameters

    • ctor: new (...args: any[]) => any

      The class to use as the first part of the name

    • method: AnyFunction

      The method to use as the second part of the name

    Returns `${string}${"." | "#"}${string}`

    A string name for the method

    Object

    class Class {
    static staticMethod() {}
    }

    name(Class, Class.staticMethod); // 'Class.staticMethod'
    class Class {
    instanceMethod() {}
    }

    name(Class, Class.prototype.instanceMethod); // 'Class#instanceMethod'
  • Get the name of a function or class.

    Time complexity: O(1)

    Space complexity: O(1)

    Parameters

    • func: AnyFunction | new (...args: any[]) => any

      The function or class to get the name for

    Returns string

    The name of func

    Object

    function func() {}

    name(func); // 'func'
    class Class {}

    name(Class); // 'Class'