How I do: export/import?

(First, it’s about of how I do things, no must(not) do this or that here!)

I know there are many more ways to deal with javascript module export/import but this is of how I use it mostly!

EXPORT

How I’m not doing it and why?

function fo…


This content originally appeared on DEV Community and was authored by Aad Pouw

(First, it's about of how I do things, no must(not) do this or that here!)

I know there are many more ways to deal with javascript module export/import but this is of how I use it mostly!

EXPORT

How I'm not doing it and why?

function foo(){}
function bar(){}
function other(){}
export {foo,bar,other}

At this way, the file has to be maintained. As soon as there are functions changing/added or removed you have to spend time to update this list X

How I do it then and why?

export function foo(){}
export function bar(){}
export function other(){}

That might be clear, there is nothing to be maintained here V

IMPORT

It depends, if there are only one or two functions to be imported then I do it this way:

import {foo,bar} from './path/to/let/say/functions.js';

If it is more then that, same story as by export. It has to be maintained and there is no need for that. X

How I do it then and why?

import * as FT from './path/to/let/say/functions.js';
//using it
FT.foo()
FT.bar()
FT.other()

This way, it is always up-to-date, and no maintenance required V

 About wildcard/namespace

I make sure it is in uppercase ,short and reflects the imported filename

So in this example FT is short and reflects the imported file Func-Tions.js

That's it about my use of javascript module export/import.

My first post here and I have more in mind but for another time!


This content originally appeared on DEV Community and was authored by Aad Pouw


Print Share Comment Cite Upload Translate Updates
APA

Aad Pouw | Sciencx (2025-01-12T07:09:55+00:00) How I do: export/import?. Retrieved from https://www.scien.cx/2025/01/12/how-i-do-export-import/

MLA
" » How I do: export/import?." Aad Pouw | Sciencx - Sunday January 12, 2025, https://www.scien.cx/2025/01/12/how-i-do-export-import/
HARVARD
Aad Pouw | Sciencx Sunday January 12, 2025 » How I do: export/import?., viewed ,<https://www.scien.cx/2025/01/12/how-i-do-export-import/>
VANCOUVER
Aad Pouw | Sciencx - » How I do: export/import?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/01/12/how-i-do-export-import/
CHICAGO
" » How I do: export/import?." Aad Pouw | Sciencx - Accessed . https://www.scien.cx/2025/01/12/how-i-do-export-import/
IEEE
" » How I do: export/import?." Aad Pouw | Sciencx [Online]. Available: https://www.scien.cx/2025/01/12/how-i-do-export-import/. [Accessed: ]
rf:citation
» How I do: export/import? | Aad Pouw | Sciencx | https://www.scien.cx/2025/01/12/how-i-do-export-import/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.