File tree Expand file tree Collapse file tree 1 file changed +64
-0
lines changed
Expand file tree Collapse file tree 1 file changed +64
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ title : Object shorthand
3+ tags : [good-practice]
4+ ---
5+ This matches the [ eslint rule] ( https://eslint.org/docs/latest/rules/object-shorthand ) .
6+
7+ Check the [ Playground] ( https://app.grit.io/studio?key=fsNvFDGI4px3u5p7VdAQZ )
8+ ``` grit
9+ engine marzano(1.0)
10+ language js
11+
12+ pair(key=$key, value=$value) as $pair where {
13+ if( $key <: $value){
14+ $pair => `$key`
15+ }else if ($value <: function($body, $parameters)){
16+ $pair => `$key($parameters) $body`,
17+ }
18+ }
19+ ```
20+
21+ Code examples:
22+ ``` js
23+ // properties
24+ var foo = {
25+ x,
26+ y: y,
27+ z: z,
28+ a: 12 ,
29+ b: a
30+ };
31+
32+ // methods
33+ var foo = {
34+ a : function () {},
35+ b : function ( x ) {},
36+ x : function y () {},
37+ y : function y () {},
38+ z : function y (x ) {},
39+ y (x ) {},
40+ " o-o " : ()=> 5
41+ };
42+ ```
43+ will become
44+ ``` js
45+ // properties
46+ var foo = {
47+ x,
48+ y,
49+ z,
50+ a: 12 ,
51+ b: a
52+ };
53+
54+ // methods
55+ var foo = {
56+ a () {},
57+ b (x ) {},
58+ x () {},
59+ y () {},
60+ z (x ) {},
61+ y (x ) {},
62+ " o-o " : ()=> 5
63+ };
64+ ```
You can’t perform that action at this time.
0 commit comments