toss / es-toolkit

A modern JavaScript utility library that's 2-3 times faster and up to 97% smaller—a major upgrade to lodash.
https://es-toolkit.slash.page
Other
7.1k stars 329 forks source link

`cloneDeep` behaves differently from `lodash-es` with prototype #795

Closed filipsobol closed 2 weeks ago

filipsobol commented 2 weeks ago

When working on PR #794 I noticed that lodash has a special handling for when a prototype is passed to the deepClone method.

This is just an FYI, as I don't have any need for this functionality.

Minimal reproduction:

import { cloneDeep as lodashDeepClone } from 'lodash-es';
import { cloneDeep } from 'es-toolkit';

console.log( lodashDeepClone( String.prototype ) ); // Results in [String: '']
console.log( cloneDeep( String.prototype ) ); // Results in {}
filipsobol commented 2 weeks ago

Actually, it works as expected when using es-toolkit/compat.