admin管理员组文章数量:1293917
I have a a list of constants which I am exporting
export const ABC="abc"
export const DEF="def"
...
Is there a way I can export them in a single line .
I am aware of something like this
const ABC="abc"
const DEF="def"
...
export {ABC,DEF...}
but is there a way something like
export {
//define constants here
}
I have a a list of constants which I am exporting
export const ABC="abc"
export const DEF="def"
...
Is there a way I can export them in a single line .
I am aware of something like this
const ABC="abc"
const DEF="def"
...
export {ABC,DEF...}
but is there a way something like
export {
//define constants here
}
Share
asked Jul 8, 2021 at 6:14
Akshay SharmaAkshay Sharma
671 silver badge5 bronze badges
5
-
maybe
module.exports = {ABC: 'abc', DEF: 'def'}
, i never tried though – boxdox Commented Jul 8, 2021 at 6:18 - 1 @boxdox - That's CJS. The above is ESM. – T.J. Crowder Commented Jul 8, 2021 at 6:18
-
What's the thing about
export { /* define constants here */ }
that you like better thanexport const ABC = "abc"; export const DEF = "def";
? To me those are basically the same. Is it the repeatedexport
? – T.J. Crowder Commented Jul 8, 2021 at 6:19 - @T.J.Crowder dang it i keep messing it up. yeah, i guess op wants to define constant inside the exports itself – boxdox Commented Jul 8, 2021 at 6:20
- Yes it would be great if I can export all at once instead of having a repeat export – Akshay Sharma Commented Jul 8, 2021 at 6:21
2 Answers
Reset to default 8You can declare multiple constants in the same line. Clever use of spacing gives you this:
// a.js
export const
ABC = "abc",
DEF = "def",
GHI = "ghi";
//b.js
import { ABC, DEF, HGI } from './a.js';
Note the ma between lines and the semicolon in the last one.
Prettier would like to have a chat with you though.
No, you have to do one of the two things you listed (export them as you declare them, or use an export declaration gathering them together). (If it helps, it doesn't matter where the export { ... }
is in relation to the constants; it can be above them if you prefer [yes, really
本文标签: javascriptIs there a way I can export multiple constantsStack Overflow
版权声明:本文标题:javascript - Is there a way I can export multiple constants - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741588493a2386981.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论