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
Parentheses serve two purposes in CoffeeScript:
- They group expressions:
(a + b) * c - 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
2 Comments
Leonid Beschastny
Here is another way to write it:
(require './routes') appmu is too short
@LeonidBeschastny: Yeah, that one too. I tend to forget that version because it looks too much like Lisp.