您的位置:首页 > 其它

use traceur in ES6

2015-07-28 22:03 204 查看
1 Index.html

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
</body>
<!-- 加载Traceur编译器 -->
<script src="http://google.github.io/traceur-compiler/bin/traceur.js" type="text/javascript"></script>
<!--<!– 将Traceur编译器用于网页 –>-->
<script src="http://google.github.io/traceur-compiler/src/bootstrap.js" type="text/javascript"></script>
<!-- 打开实验选项,否则有些特性可能编译不成功 -->
<script>
traceur.options.experimental = true;
</script>

<script type="module" src="cal.js">
</script>
</html>


2 cal.js

/**
* Created by Jackey Li on 2015/7/26.
*/
import {Hello} from './profile.js';
class Calc {
constructor(){
this.hello = new Hello();
this.hello.sayHi();
console.log('Calc constructor');
}
add(a, b){
return a + b;
}
}

var c = new Calc();
console.log(c.add(4,5));


3 profile.js

/**
* Created by Jackey Li on 2015/7/26.
*/
export class Hello{
constructor(){

}
sayHi(){
console.log('hi');
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: