I am writing a program that that serializes objects. As part of that, I need to get the class from an instance so I can create a new instance in the future. I noticed that I can either call fn.constructor or Object.getPrototypeOf(fn).constructor to get the class that the instance came from. For example:
class Foo {}
const myFoo = new Foo();
const constructor1 = myFoo.constructor;
const constructor2 = Object.getPrototypeOf(myFoo).constructor;
In the above, constructor1 and constructor2 seem to always be the same unless I manually set them to some other value. Is there a circumstance in which these values would be different?