use the constructor of a class's instance to construct a new instance.
this is useful for avoiding pollution of code with new keyword along with some wonky placement of braces to make your code work.
Example
classK { constructor(value1, value2) { this.value = value1 + value2 } } consta = newK(1, 1) constb = constructFrom(a, 2, 2) // equivalent to `const b = new K(2, 2)` constc = new (Object.getPrototypeOf(a).constructor)(3, 3) // vanilla way of constructing `const c = new K(3, 3)` using `a`
constructFrom<T, Args>(class_instance, ...args): T
use the constructor of a class's instance to construct a new instance.
this is useful for avoiding pollution of code with
new
keyword along with some wonky placement of braces to make your code work.Example