[英]How to export multiple functions as aliases in ES6
I want to export multiple functions as aliases in ES6.我想在 ES6 中将多个函数导出为别名。
I exported it like this because I want to use export default but "as" doesn't seem to work.我像这样导出它,因为我想使用导出默认值,但“as”似乎不起作用。
const fn1 = () => {};
const fn2 = () => {};
export default = {
fn1 as function1,
fn2 as function2,
} // -> not working
How can I do what I want?我怎样才能做我想做的事?
What follows export default
should be an expression (not a =
). export default
应该是一个表达式(而不是一个=
)。 So all you need to do after that is use the right syntax for a normal Javascript object:所以之后你需要做的就是对普通的 Javascript 对象使用正确的语法:
export default {
function1: fn1,
function2: fn2,
};
I think that is a wrong syntax.我认为这是错误的语法。 Correct use would be without
'='
before "{"
.正确的使用是在
"{"
之前没有'='
。
export default {
fn1 as function1,
fn2 as function2
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.