Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cloneDeep() does not preserve ES5 property attributes #3043

Closed
mbrowne opened this issue Mar 4, 2017 · 3 comments
Closed

cloneDeep() does not preserve ES5 property attributes #3043

mbrowne opened this issue Mar 4, 2017 · 3 comments
Labels

Comments

@mbrowne
Copy link

mbrowne commented Mar 4, 2017

Consider the following example:

var o = {};
Object.defineProperty(o, 'foo', {enumerable:true, writable:false, value:'f'});
var o2 = _.clone(o);

console.log(Object.getOwnPropertyDescriptor(o2, 'foo'));

The property descriptor on the copied object specifies the property as writable even though the original property wasn't writable.

I also noticed that clone() and cloneDeep() only copy enumerable properties, but that's mentioned in the documentation so I assume it's deliberate (might be nice to add an option to copy them if desired).

@jdalton jdalton added the invalid label Mar 4, 2017
@jdalton
Copy link
Member

jdalton commented Mar 4, 2017

Hi @mbrowne!

This is by design. Preserving attribute descriptors is super expensive. It's part of the tradeoffs we make for being a general purpose util.

@jdalton jdalton closed this as completed Mar 4, 2017
@mbrowne
Copy link
Author

mbrowne commented Mar 4, 2017

Thanks for the quick clarification! The docs could be clearer on this, but I just looked again and it does say that properties "are cloned as plain objects", which I'm guessing might have been meant to indicate that.

@lock
Copy link

lock bot commented Dec 27, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Dec 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

2 participants