-
Notifications
You must be signed in to change notification settings - Fork 30k
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
respose.setHeader() should return response to allow chaining #33148
Comments
this can be easily accomplished by adding |
Is this related to #25935? However, I would like to discourage this, because of the command-query separation principle; which is to say, methods that return things should not also mutate the state of the object. |
Yes, looks the same issue. However, I really don't understand why this principle should be followed in this particular case. In the case that I mentioned,
as chaining isn't allowed, must currently be written as
Chaining is a natural thing in JS. Wouldn't code like This may be closed as duplicate, if wanted. |
@SrBrahma, I'm not a contributor to nodejs project, but I can answer your question as to if |
@SrBrahma I would disagree about "natural". It's tolerated; and I know some places do promote it; but there's also a strong tradition for functional programming, and when I see code like The fact it's named |
Make `response.setHeader` return the response object itself so that multiple header setting can be chained. Fixes: #33148 PR-URL: #35924 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Ricky Zhou <[email protected]> Reviewed-By: Rich Trott <[email protected]>
Make `response.setHeader` return the response object itself so that multiple header setting can be chained. Fixes: nodejs#33148 PR-URL: nodejs#35924 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Ricky Zhou <[email protected]> Reviewed-By: Rich Trott <[email protected]>
Make `response.setHeader` return the response object itself so that multiple header setting can be chained. Fixes: #33148 PR-URL: #35924 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Ricky Zhou <[email protected]> Reviewed-By: Rich Trott <[email protected]>
Currently, response.setHeader() doesn't return anything. It really should simply return the response to allow chainings like
response.setHeader(xxx).send(yyy)
The text was updated successfully, but these errors were encountered: