babel/doc/playground.md
2014-11-26 22:21:18 +11:00

1.3 KiB

Playground

Playground is a proving ground for possible ES7 proposals.

NOTE: These features are in no way endorsed by Ecma International and are not a part of ES6. They might become a part of ECMAScript in the future.

Usage

$ 6to5 --playground
to5.transform("code", { playground: true });

NOTE: Enabling playground also enables experimental support.

Features

Memoization assignment operator

var obj = {};
obj.x ?= 2;
obj.x; // 2

obj = { x: 1 };
obj.x ?= 2;
obj.x; // 1

obj = { x: undefined }
obj.x ?= 2;
obj.x; // undefined
var obj = {};
obj.x ?= 2;

equivalent to:

var obj = {};
if (!Object.prototype.hasOwnProperty.call(obj, "x")) obj.x = 2;

Method binding

var fn = obj:method;
var fn = obj:method("foob");

["foo", "bar"].map(:toUpperCase); // ["FOO", "BAR"]
[1.1234, 23.53245, 3].map(:toFixed(2)); // ["1.12", "23.53", "3.00"]

equivalent to:

var fn = obj.method.bind(obj);
var fn = obj.method.bind(obj, "foob");

["foo", "bar"].map(function (val) { return val.toUpperCase(); });
[1.1234, 23.53245, 3].map(function (val) { return val.toFixed(2); });