File tree Expand file tree Collapse file tree 1 file changed +30
-3
lines changed Expand file tree Collapse file tree 1 file changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -3,8 +3,7 @@ title: Function expressions to arrow functions
3
3
tags : [js, es6, migration]
4
4
---
5
5
6
- Converts function expressions to ES6 arrow functions
7
-
6
+ Converts function expressions to ES6 arrow functions, including eliminating the ` return ` statement where possible.
8
7
9
8
``` grit
10
9
engine marzano(0.1)
23
22
or { `this`, `arguments` }
24
23
} until `function $_($_) { $_ }`
25
24
},
26
- `($args) => { return $value }` => `($args) => $value`
25
+ `($args) => { return $value }` where {
26
+ if ($value <: object()) {
27
+ $result = `($value)`
28
+ } else {
29
+ $result = $value
30
+ }
31
+ } => `($args) => $result`
27
32
}
28
33
```
29
34
@@ -68,3 +73,25 @@ var sumToValue = (x, y) => {
68
73
69
74
var times = (x , y ) => x * y;
70
75
```
76
+
77
+ ## Wraps objects correctly
78
+
79
+ An arrow function can return an object directly, but it must be wrapped in parentheses.
80
+
81
+ ``` js
82
+ const dummyAnswer = (type ) => {
83
+ return {
84
+ dataset : function (name , query ) {
85
+ return 1 ;
86
+ },
87
+ };
88
+ };
89
+ ```
90
+
91
+ ``` js
92
+ const dummyAnswer = (type ) => ({
93
+ dataset : (name , query ) => {
94
+ return 1 ;
95
+ },
96
+ });
97
+ ```
You can’t perform that action at this time.
0 commit comments