Best practice for wrapping function arguments
See original GitHub issueStyle guide should advise wrapping function arguments that go over maximum line length.
function someVeryLongFunctionName(someVeryLongArgumentName1, someVeryLongArgumentName2, someVeryLongArgumentName3) {
// Function body
}
or:
function myFunction(someArg1, someArg2, someArg3, someArg4, someArg5, someArg6, someArg7, someArg8) {
// Function body
}
Wrapped:
function myFunction(someArg1, someArg2, someArg3, someArg4,
someArg5, someArg6, someArg7, someArg8) {
// Function body
}
Issue Analytics
- State:
- Created 8 years ago
- Comments:11
Top Results From Across the Web
Wrapping function arguments? - c++ - Stack Overflow
Yes, it's better. You basically have a pack of variables that you need to manipulate together, and which have to be passed around...
Read more >How to Correctly Wrap a JavaScript Function - TrackJS
Wrapping JavaScript functions lets you add common logic to functions you do not control, like native and ... How do we pass function...
Read more >Strategies for parameter wrapping
Better typing; wrapping related parameters together into a single type can help clarify the meaning of the function.
Read more >JavaScript Code Styling Best Practices — Functions ...
Line breaks between arguments of a function call are only needed if the expressions that we pass in are long. For instance, if...
Read more >How to write bulletproof function wrappers in JavaScript
The solution: always pass an array of arguments to the wrapped function, matching the length of the arguments provided to the wrapper. If...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Is there any word on this? Compared to alternative which is common in PHP’s PSR to chop down like:
It’s better for version control to have one argument per line (the same reason we have trailing commas), is easer to read and is more friendly with default arguments.
Thoughts?
I suggest watching any talk by Kevlin Henney related to code formatting, noise and style. May be an eye-opener to some developers out there.