Reputation: 30
I'm trying to find out if it's okay (not bad practice) to use an exported function in the same file it's being exported and also the file it's being imported? I'm using a webpack/babel setup.
Example case:
File1.js (the file that exports the function):
export default myFunction(e) {
e.preventDefault();
// some code
}
window.onload = () => {
document.getElementById('some-element').addEventListener('change', e => myFunction(e));
}
File2.js:
import myFunction from './File1';
window.onload = () => {
document.getElementById('some-element').addEventListener('change', e => myFunction(e));
}
Upvotes: 0
Views: 95
Reputation: 1074148
Yes, it's absolutely fine to use the function both in its own module and in other modules that import it.
Upvotes: 4