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‘); } }
时间: 2024-10-12 16:56:18