我遵循了一个教程,以了解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
标记中的内容不会更改。问题是什么?
答案 0 :(得分:0)
<!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">