Skip to content

Commit 678d701

Browse files
committed
Merge pull request #2 from volv/master
ES5 Equivs
2 parents 005284f + de0c437 commit 678d701

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

arrow.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,33 @@
22
* Arrow functions have shorter syntax that function expression.
33
* These functions also lexically bind `this` value and are always anonymous.
44
*/
5-
6-
var foo = ["Hello", "World"];
5+
6+
let foo = ["Hello", "World"];
77

88
//single arguments do not require parenthesis or curly braces.
9-
var bar = foo.map(x => x.length);
9+
//The return statement is implicit
10+
let bar = foo.map(x => x.length);
11+
12+
// ES5
13+
var bar = foo.map(function(x) { return x.length; });
1014

1115
//multiline functions require curly braces
1216
//no arguments expect parenthesis
13-
var foobar = () => {
14-
console.log("Hello World")
15-
}
17+
let foobar = () => {
18+
console.log("Hello");
19+
console.log("World");
20+
};
21+
22+
// ES5
23+
var foobar = function() {
24+
console.log("Hello");
25+
console.log("World");
26+
}
27+
28+
//Returning onbject literal. Requires Brackets.
29+
let quux = () => ({ "myProp" : 123 });
30+
31+
//ES5
32+
var quux = function() {
33+
return { "myProp" : 123 };
34+
};

0 commit comments

Comments
 (0)