ES6 Singleton vs Instantiating a Class once : <p>I see patterns which make use of a singleton pattern using ES6 classes and I am wondering why I would use them as opposed to just instantiating the class at the bottom of the file and exporting the instance. Is there some kind of negative drawback to doing this? For example:</p>

<p><strong><em>ES6 Exporting Instance:</em></strong></p>

<pre><code>import Constants from '../constants';

class _API {
  constructor() {
    this.url = Constants.API_URL;
  }

  getCities() {
    return fetch(this.url, { method: 'get' })
      .then(response =&gt; response.json());
  }
}

const API = new _API();
export default API;
</code></pre>

<p><strong>Usage:</strong></p>

<pre><code>import API from './services/api-service'
</code></pre>

<p>What is the difference from using the following Singleton pattern? Are there any reasons for using one from the other? Im actually more curious to know if the first example I gave can have issues that I am not aware of.</p>

<p><strong><em>Singleton Pattern:</em></strong></p>

<pre><code>import Constants from '../constants';

let instance = null;

class API {
  constructor() {

    if(!instance){
      instance = this;
    }

    this.url = Constants.API_URL;

    return instance;
  }

  getCities() {
    return fetch(this.url, { method: 'get' })
      .then(response =&gt; response.json());
  }
}

export default API;
</code></pre>

<p><strong><em>Usage:</em></strong></p>

<pre><code>import API from './services/api-service';

let api = new API()
</code></pre>
