title: Module.export a 'default' function
body: <p>I want to write a module that exports a default function and a list of properties (they are functions too).
  Basically this module will allows this usage consumer-side:</p>
  
  <pre><code>let db_connection = fake_database_connection_instance()
  let db = require('./db.js')(db_connection)
  db.find({id:1})
  </code></pre>
  
  <p>So the default function should only pass the database connection instance to the module.
  This is the not working code</p>
  
  <pre><code>module.exports = {
      //init should go away and replaced by a 'default' function when this module is called
      init: function (connection) {
          this.connection= connection;
          return this;
      },
      find: function (query) {
          return new Promise(function (resolve, reject) {
              this.connection.find(query, function (err, docs) {
                  if (err) {
                      return reject(err);
                  }
                  return resolve(docs);
              });
          });
      }
  }
  </code></pre>
  
  <p>I want to avoid the <code>new</code> keyword (consumer-side), so I have to remove those <code>this</code>, I know. The problem here are 2:</p>
  
  <ul>
  <li>how to export a default function called on <code>require('./db.js')()</code> and other functions e.g. <code>require('./db.js').find()</code>?</li>
  <li>how pass the connection instance from the default function to <code>find()</code>?</li>
  </ul>
  
  <p><strong>EDIT</strong> following the @Igor Raush ES6 Class solution I wrote this, but still <code>db is not defined</code></p>
  
  <pre><code>class DB {
      constructor(db) {
          this.db = db;
      }
      find(query) {
          return new Promise( (resolve, reject) =&gt; {
              this.db.find(query, function (err, docs) {
                  if (err) {
                      return reject(err);
                  }
                  return resolve(docs);
              });
          });
      }
  }
  </code></pre>