Domanda

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?

È stato utile?

Soluzione

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) {
    // ...
}

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top