I was really curious about the upcoming ES6 features. After a long time, today I made time to try out some of the features using traceur-compiler.
First thing I done was to setup a boilerplate to run ES6 with traceur.
In the above traceur.js is the compiler and bootstrap.js is used for compile all the script tags with type=”text/traceur” into vanilla js.
Some of the experimental features in traceur are truned off by default, so we need to enable all the experimental features using
You can look into options for details.
Now lets create a class for calculator and define a function named add.
Hooray!! it works!!
Modules are not fully implemented on traceur, so until then, we need to use ES6 Loader polyfill.
Using Command line
If you want traceur to work on command line, You can install via npm.
And we can run it by,
This will you compile and execute the calc.js and output to terminal.
If you wanna compile to another file,
This will store the compiled js to build/calc.js. You can trun on experimental features with
If you want to set up traceur compiler with grunt, you can use grunt-traceur.
Configure traceur task
You can run it by,