-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy patharrow.js
34 lines (27 loc) · 778 Bytes
/
arrow.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* Arrow functions have shorter syntax than function expressions.
* These functions also lexically bind `this` value and are always anonymous.
*/
let foo = ["Hello", "World"];
//single arguments do not require parenthesis or curly braces.
//The return statement is implicit
let bar = foo.map(x => x.length);
// ES5
var bar = foo.map(function(x) { return x.length; });
//multiline functions require curly braces
//no arguments expect parenthesis
let foobar = () => {
console.log("Hello");
console.log("World");
};
// ES5
var foobar = function() {
console.log("Hello");
console.log("World");
};
//Returning object literal. Requires Brackets.
let quux = () => ({ "myProp" : 123 });
//ES5
var quux = function() {
return { "myProp" : 123 };
};