input
74
1
/*
2
Thanks for trying Bublé! Quickstart:
3
4
$ npm install -g buble
5
$ echo "const answer = () => 42" > input.js
6
$ buble input.js > output.js
7
$ cat output.js
8
9
This is a relatively new project – please report
10
any bugs you find by clicking 'report bugs' and
11
linking to a version of this page demonstrating
12
the issue. Thanks!
13
14
Note that some ES2015 features are deliberately
15
unsupported - click the 'guide' link in nav.
16
*/
17
18
// arrow functions
19
const add = ( a, b ) => a + b;
20
21
// classes
22
class Circle extends Shape {
23
constructor ( radius ) {
24
super();
25
this.radius = this;
26
}
27
28
area () {
29
return Math.PI * Math.pow( this.radius, 2 );
30
}
31
}
32
33
// object literals
34
let obj = {
35
shorthandProperty,
36
shorthandMethod () {
37
console.log( 'hello!' );
38
},
39
[computed]: 42
40
};
41
42
// template strings
43
let message = `
44
hello ${name}!
45
it's good to see you`;
46
47
// destructuring
48
let { x, y } = point;
49
let { top, left } = element.getBoundingClientRect();
50
let [ one, two, three ] = document.querySelectorAll( 'p' );
51
52
// default parameters
53
function foo ( options = {} ) {
54
if ( options.bar ) alert( options.baz );
55
}
56
57
// rest parameters
58
function sprintf ( str, values ) {
59
return str.replace( /%(w+)/g, ( match, type ) => {
60
return format( values.shift(), type );
61
});
62
}
63
64
// spread operator
65
var max = Math.max( values );
66
67
// block scoping
68
for ( let i = 0; i < 10; i += 1 ) {
69
const square = i * i;
70
setTimeout( () => console.log( square ), i * 100 );
71
}
72
73
// binary and octal literals
74
0b101010 === 0o52;
output
91
1
/*
2
Thanks for trying Bublé! Quickstart:
3
4
$ npm install -g buble
5
$ echo "const answer = () => 42" > input.js
6
$ buble input.js > output.js
7
$ cat output.js
8
9
This is a relatively new project – please report
10
any bugs you find by clicking 'report bugs' and
11
linking to a version of this page demonstrating
12
the issue. Thanks!
13
14
Note that some ES2015 features are deliberately
15
unsupported - click the 'guide' link in nav.
16
*/
17
18
// arrow functions
19
var add = function ( a, b ) { return a + b; };
20
21
// classes
22
var Circle = (function (Shape) {
23
function Circle ( radius ) {
24
Shape.call(this);
25
this.radius = this;
26
}
27
28
if ( Shape ) Circle.__proto__ = Shape;
29
Circle.prototype = Object.create( Shape && Shape.prototype );
30
Circle.prototype.constructor = Circle;
31
32
Circle.prototype.area = function area () {
33
return Math.PI * Math.pow( this.radius, 2 );
34
};
35
36
return Circle;
37
}(Shape));
38
39
// object literals
40
var obj = {
41
shorthandProperty: shorthandProperty,
42
shorthandMethod: function shorthandMethod () {
43
console.log( 'hello!' );
44
}
45
};
46
obj[computed] = 42;
47
48
// template strings
49
var message = "\n hello " + name + "!\n it's good to see you";
50
51
// destructuring
52
var x = point.x;
53
var y = point.y;
54
var ref = element.getBoundingClientRect();
55
var top = ref.top;
56
var left = ref.left;
57
var ref$1 = document.querySelectorAll( 'p' );
58
var one = ref$1[0];
59
var two = ref$1[1];
60
var three = ref$1[2];
61
62
// default parameters
63
function foo ( options ) {
64
if ( options === void 0 ) options = {};
65
66
if ( options.bar ) { alert( options.baz ); }
67
}
68
69
// rest parameters
70
function sprintf ( str ) {
71
var values = [], len = arguments.length - 1;
72
while ( len-- > 0 ) values[ len ] = arguments[ len + 1 ];
73
74
return str.replace( /%(w+)/g, function ( match, type ) {
75
return format( values.shift(), type );
76
});
77
}
78
79
// spread operator
80
var max = Math.max.apply( Math, values );
81
82
// block scoping
83
var loop = function ( i ) {
84
var square = i * i;
85
setTimeout( function () { return console.log( square ); }, i * 100 );
86
};
87
88
for ( var i = 0; i < 10; i += 1 ) loop( i );
89
90
// binary and octal literals
91
42 === 42;