Conditions | 1 |
Paths | 1 |
Total Lines | 128 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | define(['jquery', 'lodash', 'ig_markerfactory'], function (jQuery, _, MarkerFactory) { |
||
5 | jQuery(document).ready(function () { |
||
6 | |||
7 | var icons_fontello = { |
||
|
|||
8 | camera: MarkerFactory.autoIcon({ |
||
9 | label: 'e810', |
||
10 | font: 'fontello', |
||
11 | color: '#CC0000', |
||
12 | fontsize: 30, |
||
13 | scale: 1, |
||
14 | transparent_background: true |
||
15 | }), |
||
16 | retail: MarkerFactory.autoIcon({ |
||
17 | label: 'e896', |
||
18 | font: 'fontello', |
||
19 | color: '#33CCCC', |
||
20 | fontsize: 30, |
||
21 | scale: 1, |
||
22 | transparent_background: true |
||
23 | }), |
||
24 | plane: MarkerFactory.autoIcon({ |
||
25 | label: 'e892', |
||
26 | font: 'fontello', |
||
27 | color: '#CC00FF', |
||
28 | fontsize: 30, |
||
29 | scale: 1, |
||
30 | transparent_background: true |
||
31 | }), |
||
32 | taxi: MarkerFactory.autoIcon({ |
||
33 | label: 'e88c', |
||
34 | font: 'fontello', |
||
35 | color: '#33CC33', |
||
36 | fontsize: 30, |
||
37 | scale: 1, |
||
38 | transparent_background: true |
||
39 | }) |
||
40 | }, |
||
41 | icons_fontawesome = { |
||
42 | camera: MarkerFactory.autoIcon({ |
||
43 | label: 'f030', |
||
44 | font: 'FontAwesome', |
||
45 | color: '#CC0000', |
||
46 | fontsize: 30, |
||
47 | scale: 1, |
||
48 | transparent_background: true |
||
49 | }), |
||
50 | retail: MarkerFactory.autoIcon({ |
||
51 | label: 'f07a', |
||
52 | font: 'FontAwesome', |
||
53 | color: '#33CCCC', |
||
54 | fontsize: 30, |
||
55 | scale: 1, |
||
56 | transparent_background: true |
||
57 | }), |
||
58 | plane: MarkerFactory.autoIcon({ |
||
59 | label: 'f072', |
||
60 | font: 'FontAwesome', |
||
61 | color: '#CC00FF', |
||
62 | fontsize: 30, |
||
63 | scale: 1, |
||
64 | transparent_background: true |
||
65 | }), |
||
66 | taxi: MarkerFactory.autoIcon({ |
||
67 | label: 'f1ba', |
||
68 | font: 'FontAwesome', |
||
69 | color: '#33CC33', |
||
70 | fontsize: 30, |
||
71 | scale: 1, |
||
72 | transparent_background: true |
||
73 | }) |
||
74 | }, |
||
75 | icons_material = { |
||
76 | camera: MarkerFactory.autoIcon({ |
||
77 | label: 'E3B0', |
||
78 | font: 'Material Icons', |
||
79 | color: '#CC0000', |
||
80 | fontsize: 40, |
||
81 | scale: 1, |
||
82 | transparent_background: true |
||
83 | }), |
||
84 | retail: MarkerFactory.autoIcon({ |
||
85 | label: 'E8CC', |
||
86 | font: 'Material Icons', |
||
87 | color: '#33CCCC', |
||
88 | fontsize: 40, |
||
89 | scale: 1, |
||
90 | transparent_background: true |
||
91 | }), |
||
92 | plane: MarkerFactory.autoIcon({ |
||
93 | label: 'E195', |
||
94 | font: 'Material Icons', |
||
95 | color: '#CC00FF', |
||
96 | fontsize: 40, |
||
97 | scale: 1, |
||
98 | transparent_background: true |
||
99 | }), |
||
100 | taxi: MarkerFactory.autoIcon({ |
||
101 | label: 'e531', |
||
102 | font: 'Material Icons', |
||
103 | color: '#33CC33', |
||
104 | fontsize: 40, |
||
105 | scale: 1, |
||
106 | transparent_background: true |
||
107 | }) |
||
108 | }; |
||
109 | |||
110 | |||
111 | _.each(icons_fontello, function (icon, name) { |
||
112 | var theimage = jQuery('<img>'); |
||
113 | theimage.attr('src', icon.url); |
||
114 | jQuery('#fontello').find('.' + name).append(theimage); |
||
115 | }); |
||
116 | |||
117 | _.each(icons_fontawesome, function (icon, name) { |
||
118 | var theimage = jQuery('<img>'); |
||
119 | theimage.attr('src', icon.url); |
||
120 | jQuery('#fontawesome').find('.' + name).append(theimage); |
||
121 | }); |
||
122 | |||
123 | _.each(icons_material, function (icon, name) { |
||
124 | var theimage = jQuery('<img>'); |
||
125 | theimage.attr('src', icon.url); |
||
126 | jQuery('#materialicons').find('.' + name).append(theimage); |
||
127 | }); |
||
128 | |||
129 | |||
130 | |||
131 | |||
132 | }); |
||
133 | |||
136 |
Since ECMAScript 6, you can create block-scoped vars or constants with the keywords
let
orconst
. These variables/constants are only valid in the code block where they have been declared.Consider the following two pieces of code:
and
The variable is not defined otuside of its block. This limits bleeding of variables into other contexts.
To know more about this ECMA6 feature, look at the MDN pages on let and const.