Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upissue #1673 Method chaining #1682
Open
Conversation
| @@ -1111,6 +1111,8 @@ Other Style Guides | |||
| <a name="constructors--chaining"></a><a name="9.3"></a> | |||
| - [9.3](#constructors--chaining) Methods can return `this` to help with method chaining. | |||
|
|
|||
| > When? Use chaining when functions manipulate the internals of an object instead of just returning data. | |||
This comment has been minimized.
This comment has been minimized.
ljharb
Dec 26, 2017
Collaborator
Definitely not "only use", because (for example) all the non-mutating array methods are perfect chaining candidates but do not manipulate any internals.
In general, this section may need to be reworked to suggest making classes immutable (ie, to always return a new instance, allowing chaining and also avoiding mutation). However that shouldn't go in this PR.
README.md
Outdated
| @@ -1142,7 +1144,8 @@ Other Style Guides | |||
| const luke = new Jedi(); | |||
| luke.jump() | |||
| .setHeight(20); | |||
| .setHeight(20); // same as var tmp = luke.jump(); tmp.setHeight(20); | |||
| // executes left to right. First jump() and then setHeight() | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Fatehsandhu
Dec 26, 2017
Author
@ljharb I agree with you that line 1148 can be removed. Is that okay?
erights
commented
Dec 26, 2017
|
I'm ok with removing the comment. The reason I liked it is as an indirect reminder that it does not mean: luke.jump();
luke.setHeight(20);but it's probably better just to be explicit about this. |
README.md
Outdated
| @@ -1142,7 +1144,7 @@ Other Style Guides | |||
| const luke = new Jedi(); | |||
| luke.jump() | |||
| .setHeight(20); | |||
| .setHeight(20); // same as var tmp = luke.jump(); tmp.setHeight(20); | |||
This comment has been minimized.
This comment has been minimized.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.


Fatehsandhu commentedDec 26, 2017
•
edited by ljharb
@ljharb @erights Can you guys let me know if this correct?
Thanks!
Fixes #1673.