2016-07-11 34 views
0

我正在嘗試traceur hello world Getting Started頁面的示例。這是我的代碼。在Traceur中快速編譯定義全局值

<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> 

而main.js有這樣的:

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

現在,當我在控制檯檢查的值,它正確地顯示但foo是不確定的。我知道這裏發生了什麼,main.js文件沒有在全局範圍內執行,所以function聲明也不會註冊爲全局範圍。

我希望能夠從包含文件中聲明全局類和函數。

回答

0

我可以圍繞一個簡單的

window.foo = function() {}