0

I have this code for making a post request, sending some data, and logging the return value

$.post '/saveletter', {start: {x: startX, y:startY}, letter: currentLetter, unitVectors: letter.unitVectorsJson(), timeVectors: letter.timeVectorsJson()}, (data) =>
  console.log data

I want to split the long parameter object into several lines, for better readability, but can't figure out the syntax that will work.

1 Answer 1

4

To make your code more readable, you can use the following (fiddle and compiled result):

$.post '/saveletter',
    start:
        x: startX
        y: startY
    letter: currentLetter
    unitVectors: letter.unitVectorsJson()
    timeVectors: letter.timeVectorsJson()
, (data) =>
  console.log data​​

In Coffeescript, { and } may be omitted from the object literal. And commas may be exchanged for newlines (within an object literal, not between arguments).

The following is also valid, but might be less readable (ie not obvious at the first glance):

start: x: startX, y: startY
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.