Skip to content

Use ES7 spread properties to make shallow clones of objects.#44

Open
benjamn wants to merge 1 commit into
Khan:masterfrom
benjamn:patch-1
Open

Use ES7 spread properties to make shallow clones of objects.#44
benjamn wants to merge 1 commit into
Khan:masterfrom
benjamn:patch-1

Conversation

@benjamn

@benjamn benjamn commented Nov 27, 2015

Copy link
Copy Markdown

I don't know if you have ES7 object rest/spread properties enabled, but, if you do, here's an easy ES7 idiom for creating a new object with all the same own properties of a given object.

Specification: https://github.com/sebmarkbage/ecmascript-rest-spread

I don't know if you have ES7 object rest/spread properties enabled, but, if you do, here's an easy ES7 idiom for creating a new object with all the same own properties of a given object.

Specification: https://github.com/sebmarkbage/ecmascript-rest-spread
Comment thread style/javascript.md

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this was the last use of footnote 3 -- can you delete that footnote? (after confirming it really was the last.)

@csilvers

Copy link
Copy Markdown
Member

I don't know very much about clone(), but does it do a deep copy or a shallow copy? The spread property only does a shallow copy, right?

@jeresig

jeresig commented Jan 19, 2016

Copy link
Copy Markdown
Member

Yep - _.clone() is equivalent, so this could work. I think most of the cases that I've seen, that we had, were actually _.deepClone(). But there's no harm in adding this, as well. Would be good to delete (and re-org) the footnotes.

@ariabuckles

Copy link
Copy Markdown
Contributor

Perseus uses _.clone and, more commonly, _.merge pretty extensively, but has very few if any deepClones :). I think this is useful if we have es7 spread enabled.

@csilvers

Copy link
Copy Markdown
Member

OK, great -- once the footnoes are cleaned up I'll merge this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants