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

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

benjamn
Copy link

@benjamn benjamn commented Nov 27, 2015

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
@@ -567,7 +567,7 @@ Method | Use... | ...instead of
bind | `fn.bind(someObj, args)` | `_.bind(fn, someObj, args)`
bind | `(a, b) => { ... }` <sup>[1](#u1)</sup> | `_.bind(function(a, b) { ... }, this)`
bindAll | `obj.method = obj.method.bind(someObj);` <sup>[2](#u2)</sup> | `_.bindAll(someObj, "method")`
clone | No alternative at the moment! <sup>[3](#u3)</sup> |
Copy link
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
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
Copy link
Member

jeresig commented Jan 19, 2016

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
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
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.

None yet

4 participants