1

I have several functions in a CoffeeScript module:

func1 = () -> ...
func2 = () -> ...
func3 = () -> ...
func4 = () -> ...

If I want to make it clear where they come from (without searching for a definition), I'd avoid making them global (@func1 = ..., @func2 = ...) , and stick to a more explicit syntax:

helpers = require('/lib/helpers.coffee')

But this requires something like

meteor.exports.func1 = func1

repeated every time. Or

meteor.exports.func1 = () -> ...

But this way it's harder to make calls between them here inside.

I know ES6 has an elegant syntax like {var1, var2, ...}, but is there something similar in CoffeeScript?

1 Answer 1

2
func1 = () ->
func2 = () ->
module.exports = {func1, func2}

compiled to:

var func1, func2;
func1 = function() {};
func2 = function() {};
module.exports = {
  func1: func1,
  func2: func2
};

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.