I have several functions in a CoffeeScript module:
我在CoffeeScript模块中有几个函数:
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:
如果我想清楚它们来自哪里(不搜索定义),我会避免将它们设为全局(@ func1 = ...,@ func2 = ...),并坚持使用更明确的语法:
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?
我知道ES6有一个优雅的语法,如{var1,var2,...},但在CoffeeScript中有类似的东西吗?
1 个解决方案
#1
1
func1 = () ->
func2 = () ->
module.exports = {func1, func2}
compiled to:
var func1, func2;
func1 = function() {};
func2 = function() {};
module.exports = {
func1: func1,
func2: func2
};
#1
1
func1 = () ->
func2 = () ->
module.exports = {func1, func2}
compiled to:
var func1, func2;
func1 = function() {};
func2 = function() {};
module.exports = {
func1: func1,
func2: func2
};