Creating new instance of the same class as an existing instance, without using eval()
Advertisements I have an instance sampleInstance of an unknown class and I need to create a second instance of the same class. Here’s what I am doing right now: I look up the class name with sampleInstance.constructor.name. Next, I use eval(`new ${sampleInstance.constructor.name}()`) to create a new instance of the same class. The code below works… Read More Creating new instance of the same class as an existing instance, without using eval()