OK. I need to document some product, which is in JS, but I'm a little clumsy with the languge. There are code blocks in the documentation and I need to break some lines (they have huge tails in PDF). In Python I can do the following:

foo(bar1,
    bar2)

Can I do so in JavaScript? What are general recommendations on breaking long lines in JS?

有帮助吗?

解决方案

Yes you may use line breaks with commas as you have written. Here is an example from the Google JavaScript Style Guide.

// Parenthesis-aligned, one argument per line.  Emphasizes each
// individual argument.
function bar(veryDescriptiveArgumentNumberOne,
             veryDescriptiveArgumentTwo,
             tableModelEventHandlerProxy,
             artichokeDescriptorAdapterIterator) {
    // ...
}

其他提示

You could do that with JavaScript. Like Python, JavaScript will understand the brackets. I personally recommend writing comments before or after a method, not within its definition. If you give your comments their own space, your code will become quite clear, however adding the comments inline can be quite messy.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top