• get the prototype object of a class.
    this is useful when you want to access bound-methods of an instance of a class, such as the ones declared as: class X { methodOfProto(){ } }.
    these bound methods are not available via destructure of an instance, because they then lose their this context.
    the only functions that can be destructured without losing their this context are the ones declared via assignment: class X { fn = () => { }, fn2 = function(){ } }

    Type Parameters

    • T
    • Args extends any[] = any[]

    Parameters

    Returns PrototypeOf<ConstructorOf<T, Args>>

    Example

    const array_proto = prototypeOfClass(Array<number>)
    let arr = [1, 2, 3, 4, 5]
    array_proto.push(arr, 6)
    console.log(arr) // [1, 2, 3, 4, 5, 6]
    const push_to_arr = array_proto.push.bind(arr) // more performant than `push_to_arr = (value) => (arr.push(value))`, and also has lower memory footprint
    push_to_arr(7, 8, 9)
    console.log(arr) // [1, 2, 3, 4, 5, 6, 7, 8, 9]

Generated using TypeDoc