1

Code require ('./routes') app compiles to require('./routes'(app)); But I need it to compile to require('./routes)(app). How could I do that?

1 Answer 1

4

Parentheses serve two purposes in CoffeeScript:

  1. They group expressions: (a + b) * c
  2. They're used to call functions: f(x).

When you say this:

f (x)

there is some ambiguity about what the parentheses around x mean; are they grouping parentheses or function calling parentheses? CoffeeScript chooses the former as you've seen.

If you want (or need) to use parentheses for calling a function, you don't want a space before the opening parenthesis, you want:

f(x)

In your case you'd want:

require('./routes') app

or even:

require('./routes')(app)
(require './routes') app
Sign up to request clarification or add additional context in comments.

2 Comments

Here is another way to write it: (require './routes') app
@LeonidBeschastny: Yeah, that one too. I tend to forget that version because it looks too much like Lisp.

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.