Code migration from ES5 to ES2015 with namespace
<p>We have a cross-platform application based on <a href="https://www.polymer-project.org/0.5/" rel="nofollow">Polymer</a> and <a href="https://bitbucket.org/chromiumembedded/cef/" rel="nofollow">Chromium</a>.</p>

<p>Currently all our JavaScript dependencies are maintained in <code>index.html</code> by importing them in the <strong>right</strong> order! This approach will be a nightmare soon and writing test and to see the test coverage isn't a easy task.</p>

<p>To be future save we decided to jump on <a href="http://www.ecma-international.org/ecma-262/6.0/" rel="nofollow">ES2015</a> with it's modularity approach. </p>

<p>Now we need to redesign our JavaScript files to be able to maintain the dependencies between single JavaScript modules. So far so good. But how do we do that to preserve our namespaces, closures etc.?</p>

<p>This is a sample code:</p>

<pre><code>//namespace check
var app_ns = app_ns || { };

// ****************************************************************************
// Module: app
// ****************************************************************************

app_ns.app = (function initialize () {

  // ***
  // basic APIs and definitions
  // ***

  // Application version will be replaced by Gruntfile task.
  // Don't change the version manually!!!
  var AW_VERSION = "1.4.32";

  function version () { return AW_VERSION; }
  ...

  // ***
  // exports
  // ***
  return {
    version : version
  };  
}());
</code></pre>

<p>As you can see from the code above the initialization is executed and assigned to <code>app_ns.app</code>. Due to simplicity, the code snippet doesn't show dependencies to other modules but we have those for sure!</p>

<p>So the questions are</p>

<ul>
<li>How to use namespaces in ES2015</li>
<li>How to automatically execute closures</li>
<li>How to export functions of the modules but not in the global scope!</li>
</ul>

<p>Using <code>export { xxx };</code> is exporting all functions inside <code>{...}</code> in the global scope, right? How to bind the exported functions to the correct <strong>namespace</strong>? In this example to <code>app_ns.app</code></p>