从ECMA6到ECMA5的traceur转换无效

时间:2015-05-08 05:22:41

标签: javascript html ecmascript-6 traceur

我遵循了一个教程,以了解traceur编译器如何将ECMA6转换为ECMA5。

以下是代码。

<!DOCTYPE html>
<html>
<head>
    <title>hello world!</title>

    <script src="https://traceur-compiler.googlecode.com/git/bin/traceur.js"
        type="text/javascript"></script> 
    <script src="https://traceur-compiler.googlecode.com/git/src/bootstrap.js"
        type="text/javascript"></script> 
</head>
<body>
     <h1 id="message">This content is going to change</h1>
    <script type="text/traceur">
      class Greeter {
        constructor(message) {
          this.message = message;
        }

        greet() {
          let element = document.querySelector('#message');
          element.innerHTML = this.message;
        }
      };

      let greeter = new Greeter('Helllllllo, world!');
      greeter.greet();
    </script>

</body>
</html>

但是当我在firefox或chrome中加载页面时,h1标记中的内容不会更改。问题是什么?

1 个答案:

答案 0 :(得分:0)

好吧好像脚本网址存在问题。在github中使用了不同的教程后,这对我有用。

<!DOCTYPE html>
<html>
<head>
    <title>hello world!</title>

    <script src="https://google.github.io/traceur-compiler/bin/traceur.js"></script>
    <script src="https://google.github.io/traceur-compiler/src/bootstrap.js"></script>

</head>
<body>
     <h1 id="message">This content is going to change</h1>
    <script type="module">
      class Greeter {
        constructor(message) {
          this.message = message;
        }

        greet() {
          let element = document.querySelector('#message');
          element.innerHTML = this.message;
        }
      };

      let greeter = new Greeter('Helllllllo, world!');
      greeter.greet();
    </script>

</body>
</html>

它也适用于<script type="text/traceur">