How to import a module in es6 that itself needs to invoke/initialize its function/class before being imported
<p>I was wondering what is the best practice to import a module's function/class in another module that the module itself needs to invoke/initialize its own function/class before being imported into another module? I don't know if I could ask my question clearly enough! So let's put it in an example.</p>

<p>This is my module:</p>

<pre><code>// myModule.js
class MyModule {
  constructor() {
    // do sth
  }
}

let myModule = new MyModule();
</code></pre>

<p>And this is how I like to import it in another module:</p>

<pre><code>import MyModule from './myModule';
</code></pre>

<p>This actually works fine! But as you can see, in the <code>myModule.js</code> file I didn't <code>export default</code> my <code>MyModule</code> class because that's not the only thing that is happening in the <code>myModule.js</code> file! I'm also initializing the class after defining it... (I know that even if I have set my class as <code>export default</code> the initializing would still work fine while the module is imported somewhere else...)</p>

<p>So, without setting anything as exported inside of our module, or with setting the class as the <code>export default</code>, everything works fine when the module has been imported somewhere else... So far so good! But I'm looking for a best practice if there's one!</p>

<p>So here are my questions regarding such cases:</p>

<ol>
<li>Is it ok to import a module that doesn't have anything for export?  </li>
<li>Shall we set the class as the <code>export default</code>, although we are doing some more works outside of the class in the module (The initializing job that is happening after defining the class)?  </li>
<li>Or maybe is it good to do the initializing job in another function and then export both, the class and the function, and then invoke the function to do the initializing job in the imported module?  </li>
</ol>

<p>Thanks a lot everyone! I really appreciate any helps regarding this :)</p>