• Introduce an intermediate prototype to the target object and that sets the toStringTag on that prototype, this avoids directly modifying the target object and also allows multiple different "types" to be applied to the same target object if required. This is done as a best effort approach and may not always succeed due to security / object model restrictions So if it fails then it will fallback to just defining the toStringTag on the target object, which also may fail resulting in no change.

    Type Parameters

    • T

    Parameters

    • target: T

      The object to set the toStringTag symbol on

    • name: string

      The name or function to use for the toStringTag

    Returns T

    The target object