babel/FEATURES.md
2014-09-29 20:38:38 +10:00

1.6 KiB

Features

Arrow functions

arr.map(x => x * x);

Classes

class Foo extends Bar {
  constructor() { }

  foo() { }

  get bar() { }

  set bar() { }
}

Default parameters

function foo(bar = "foo") {
  return bar + "bar";
}

Spread

function add(x, y) {
  return x + y;
}

var numbers = [5, 10]
add(...numbers); // 15

Block binding

for (let i in arr) {
  let v = arr[i];
}

Property method assignment

var obj = {
  bar: "foobar",

  foo() {
    return "foobar";
  },

  get bar() {

  },

  set bar() {

  }
};

Rest parameters

function printList(name, ...items) {
  console.log("list %s has the following items", name);
  items.forEach(function (item) {
    console.log(item);
  });
};

Template literals

var x = 5;
var y = 10;
console.log(`${x} + ${y} = ${x + y}`); // "5 + 10 = 15"

Modules

Numeric Literals

0b111110111 === 503; // true
0o767 === 503; // true

For-of

Constants

Computed property names

var obj = {
  ["x" + foo]: "heh",
  ["y" + bar]: "noo",
  foo: "foo",
  bar: "bar"
};

Property name shorthand

function f(x, y) {
  return { x, y };
}

Array comprehension

[for (i of [1, 2, 3]) i * i]; // [1, 4, 9]

Destructuring

var [a, [b], c, d] = ["hello", [", ", "junk"], ["world"]];
console.log(a + b + c); // hello, world

Generators