New Javascript direction
This is to quickly summerize my recent thinking into using JS. There're many options, coffeescript, typescript, even livescript. Liked all of them. But I in general like something plain. So this suites me better:
- Babel to enable ES6 and ES7 (async-await)
- bluebird to promisify Node APIs
This generally solves the problem of callback hell. Promises was a step further. But ultimately it comes to async-await. I'm not too worried about type safety, which TypeScript provides. But the requirement of .d.ts
declarations scared me away. No thank you. Maybe later.
In .babelrc
:
1 | { |
In package.json
:
1 | { |
In test.es6
:
1 | require('babel-polyfill'); |
Now run:
1 | > babel test.es6 -o test.js --source-maps |
Note that async await needs polyfill the app, and hence the require('babel-polyfill');
statement at the beginning of the script. Note that polyfill only needs to be done once for the app. So if you don't want to pollute the business logic code base, write a opt-level wrapper to polyfill and call the actuall logic.