javascripttraceur

Define global values in Traceur on the fly compilation


I am trying traceur hello world example from their Getting Started page. Here's my code.

<script src="https://google.github.io/traceur-compiler/bin/traceur.js"></script>
<script src="https://google.github.io/traceur-compiler/bin/BrowserSystem.js"></script>
<script src="https://google.github.io/traceur-compiler/src/bootstrap.js"></script>
<script type="module">
  import 'main.js';
</script>

And main.js has this:

window.a = 10;
function foo() {}

Now when I check value of a in console, it shows correctly But foo is undefined. I understand what's happening here, the main.js file is not being executed in global scope so function declarations don't register for global scope either.

I would like to be able to declare global classes and functions from within included files.


Solution

  • I can get around that with a simple

    window.foo = function() {}