3

I have written this function in coffeescript:

doCalculate = (old, new) ->
  difference = roundNumber (old - new, 5)

but when compiled generates the error:

throw Error("ExecJS::RuntimeError: SyntaxError: unexpected ,

If I remove the , 5 part I get no error any more.

I can't figure what's wrong with a comma.

The function roundNumber is defined as follows, in the same file:

 roundNumber = (rnum, rlength = 6) ->
   pow = Math.pow( 10, rlength )
   newnumber = Math.round ( rnum * pow ) / pow
   parseFloat(newnumber)
3
  • 1
    do roundNumber(entry - exit, 5) Commented Jun 11, 2013 at 10:18
  • 1
    The error happens regardless I use the default value in rlength or not. Commented Jun 11, 2013 at 10:18
  • possible duplicate of Coffeescript: invoking function with space before parens Commented Jun 11, 2013 at 16:10

1 Answer 1

3

ahhhh I figured it out. coffeescript requires that there is no space between the function name and the open parenthesis.

it even works with no parentheses at all.

but not if there's a space between the function name and the (.

this works:

difference = roundNumber old - new, 5

Thanks :)

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.