This directory is temporary until we rework the front-end build This is where we are headed.
Your file needs to:
.jsx
extension.function foo(paths) {
return <svg>{paths}</svg>;
}
var arr = ['hydrogen', 'helium', 'lithium'];
// es5
var a = arr.map(function(s){ return s.length });
// es6
var b = arr.map( s => s.length );
// with curlies requires normal return
var b = arr.map( (s) => {
return s.length
});
// lexical `this`
var obj = {
multiplier: 3,
multiplyStuff (stuff) {
return stuff.map((x) =>
// no bind!
return this.multiplier * x;
)
}
};
class EventEmitter {
constructor() {
// called when created
}
emit() {
// ...
}
on() {
// ...
}
once() {
// ...
}
removeListener() {
// ...
}
removeAllListeners() {
// ...
}
}
Extending and calling super
.
class Domain extends EventEmitter {
constructor() {
super();
this.members = [];
}
}
Creating instances
var domain = new Domain();
// es5
var map = _.map;
var each = _.each;
// es6
var {map, each} = _;
// es5
var obj = {
foo: function() {}
bar: function() {}
};
// es6
var obj = {
foo() {}
bar() {}
};
// es5
function() {
// ...
return {foo: foo, bar: bar, x: 10};
}
// es6
function() {
// ...
return {foo, bar, x: 10};
}
// es5
function multiply(multiplier) {
var numbers = Array.prototype.slice.call(arguments, 0);
return number.map(function(n) { return multiplier * n; });
}
// es6
function multiply(multiplier, ...numbers) {
return numbers.map( n => multiplier * n);
}
Multiline strings:
// es5
console.log("string text line 1" +
"string text line 2");
// es6
console.log(`string text line 1
string text line 2`);
Interpolated strings
var a = 5;
var b = 10;
// es5
console.log("Fifteen is " + (a + b) + " and not " + (2 * a + b) + ".");
// es6
console.log(`Fifteen is ${a + b} and not ${2 * a + b}.`);