planttheidea / fast-copy

A blazing fast deep object copier
MIT License
1.13k stars 31 forks source link

safety around constructing with object constructor #20

Closed planttheidea closed 5 years ago

planttheidea commented 5 years ago

Trying to clone a hash generated by the node crypto package throws an error, whereas in lodash it handles it just fine. It appears that is because lodash uses toString-based tags to determine what clone to produce, which means a standard POJO is being created. Wrapping the new object.constructor() in a try prevents the error from occurring and allows the fallback of using Object.create to create the clone.

Should fix #19