Skip to content
Fred Chien edited this page Sep 30, 2015 · 3 revisions

Lantern is widely using ECMAScript 6 and 7, so you might need to know a little bit before working on your new service. We wrote down comparison here for your reference.

Import Files and Modules

Traditional:

var foo = require('foo');

ES6:

import foo from 'foo';

Export Object

Traditional:

module.exports = {};

ES6:

export default {};

Anonymous Function

Traditional:

function() {
    // Do something...
}

ES6:

() => {
    // Do something...
}

Generator Function

The generator is a new feature in ECMAScript 6, it provides a special function which can be exited and later re-entered. Node.js 0.12+ and io.js natively support such syntax, but browser supports it by using babel.

All of route handlers of Koa are using generator

function *() {
    // Do something...
}