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

Add example of destructuring assignment in constructors for easy options initialization #2378

Merged
merged 1 commit into from
Mar 5, 2013

Conversation

gabehollombe
Copy link
Contributor

Per our conversation: #1607 (comment)

@gabehollombe
Copy link
Contributor Author

@jashkenas Just following up on this after I posted it a few weeks ago. No rush, but is there anything else I can change here to help get this feature into the documentation?

@@ -0,0 +1,4 @@
class Person
constructor: (options) ->
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm pretty sure ({@name, @age, @height}) works.

@gabehollombe
Copy link
Contributor Author

It does, @Nami-Doc, but @jashkenas feels it's too esoteric, and I agree.

@jashkenas
Copy link
Owner

I'll merge when I get a chance -- otherwise, if you'd like to tweak so that it can be merged directly ... it'd be nice to make it clear that destructuring onto this is useful from any object method, not just constructors.

@michaelficarra
Copy link
Collaborator

@jashkenas: any function at all

@jashkenas
Copy link
Owner

Any function with a meaningful this, certainly.

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