0

The following gives a syntax error related to the anonymous function:

my_function = (f, x, str) ->
  alert str + f(x)

my_function (x) -> 1 + x, 12, "The answer is: "

The following works:

my_function = (f, x, str) ->
  alert str + f(x)

increment = (x) -> x + 1

my_function increment, 12, "The answer is: "
1

1 Answer 1

3
my_function ((x) -> x + 1), 12, "The answer is: "

That should fix it.

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.