我正在尝试导出 ES6 中函数的结果。该函数并不重要 - 以下示例适用于:const func = input => input
这个有效:
const a = 'foo'
const b = 'bar'
export default {
a: func(a),
b: func(b)
}
而这些遇到错误:SyntaxError: Unexpected token, expected ,
:
export {
a: func(a),
b: func(b)
}
还有:
export {
func(a) as a,
func(b) as b
}
你能解释一下为什么吗? This似乎没有涵盖上述情况。
最佳答案
你可以做到
const aArg = 'foo'
const bArg = 'bar'
export const a = func(aArg);
export const b = func(bArg);
命名导出需要一个变量名来导出,它们不能导出任意表达式结果。
关于javascript - ES6 导出函数的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43476774/