Monday, May 20, 2024
149
rated 0 times [  151] [ 2]  / answers: 1 / hits: 197934  / 6 Years ago, mon, april 2, 2018, 12:00:00

I'm creating a unit converter, and I want to put all of the conversion functions into their own file. Using ES6 export, is there any way to export all of the functions in the file with their default names using only one line? For example:



export default all;



The functions are all just in the file, not within an object.


More From » ecmascript-6

 Answers
8

No, there's no wildcard export (except when you're re-exporting everything from another module, but that's not what you're asking about).



Simply put export in front of each function declaration you want exported, e.g.



export function foo() {
// ...
}
export function bar() {
// ...
}


...or of course, if you're using function expressions:



export var foo = function() {
// ...
};
export let bar = () => {
// ...
};
export const baz = value => {
// ...
};

[#54795] Thursday, March 29, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kaleyv

Total Points: 259
Total Questions: 99
Total Answers: 107

Location: Saint Helena
Member since Tue, Nov 3, 2020
4 Years ago
;