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

Object.assign() - mention similarity to _.extend()? #99

Closed
bregenspan opened this issue Dec 25, 2014 · 5 comments

Comments

@bregenspan
Copy link
Contributor

commented Dec 25, 2014

Since so many people use Underscore.js and jQuery and they call their mixin() methods extend(), it might be useful to mention the word "extend" as a synonym of "mixin" in the Object.assign() discussion.

(I guess mentioning specific libraries might complicate the discussion too much, since although the Underscore one is totally equivalent to Object.assign(), the jQuery one isn't due to supporting deep copy).

@bregenspan bregenspan changed the title Object.assign() - mention similarity to _.extend() Object.assign() - mention similarity to _.extend()? Dec 25, 2014

@nzakas

This comment has been minimized.

Copy link
Owner

commented Dec 25, 2014

Yeah, I've purposely left out mentions of libraries. That's a pretty deep rabbit hole of a discussion that I don't think adds much to the content. "extend" is really a bad name for the operation anyway.

@nzakas nzakas closed this Dec 25, 2014

@xjamundx

This comment has been minimized.

Copy link
Contributor

commented Dec 26, 2014

I agree the section stands pretty strong on its own, but I'd maybe suggest a few tweaks that may make it a little clearer:

Many JavaScript libraries have a mixin method similar to this:

Maybe add a brief cross-reference to the extend idea here:

  • "Many JavaScript libraries have a mixin or extend method similar to this:"
  • "Many JavaScript libraries have a mixin method similar to this (often with the name extend):"

which behaves the same way.

Maybe change this to "which behaves similarly", because it accepts multiple sources and therefore is different from the mixin() example provided?

This pattern became popular enough that ECMAScript 6 added Object.assign(), which behaves the same way. The difference in name is to reflect the actual operation that occurs. Since the mixin() method uses the assignment operator (=), it cannot copy accessor properties to the receiver as accessor properties. The name Object.assign() was chosen to reflect this distinction.

I found this the trickiest sentence in this section. What about simplifying a bit to say the following:

"This pattern became popular enough that ECMAScript 6 added Object.assign(), which behaves the same way. It was given to the name Object.assign instead of Object.mixin to reflect the fact that it uses the assignment operator (=) to transfer properties."

And then leave all of the messy details about the limitations of the assignment operator to the Working with Accessor Properties box?

(References I used for my suggestions above)
http://www.2ality.com/2014/01/object-assign.html
https://mail.mozilla.org/pipermail/es-discuss/2012-December/027037.html

@nzakas

This comment has been minimized.

Copy link
Owner

commented Dec 26, 2014

Can you file a separate issue or two for your concerns so I can track them?

@xjamundx

This comment has been minimized.

Copy link
Contributor

commented Dec 26, 2014

absolutely.

@ORESoftware

This comment has been minimized.

Copy link

commented Sep 12, 2015

_.extend was always a misnomer. it should have been _.expand or whatever.

_.extend is for mixins not for inheritance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.