Closed niftylettuce closed 3 months ago
This would require a new option. The proto
option allows to copy prototype properties, not the prototype itself. It was meant as a performance improvement (that is mostly not required with the latest implementation).
Adding an option like that might be a good idea but it would likely be significantly slower. I can also imagine that I currently miss some edge cases that could not fully be handled even when cloning the prototype (we should probably also copy properties with the correct property descriptor, if we add such a mode).
You can now do this as of v1.4.0:
const clone = rfdc({
constructorHandlers: [
[ObjectId, (o) => new ObjectId(o)],
],
});
Right now, even with
{ proto: true }
, ObjectId's are cloned inaccurately, resulting in errors like this when one attempts to evenconsole.log
them after they have been cloned: