Conditions | 1 |
Paths | 1 |
Total Lines | 77 |
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 | /** |
||
4 | module.exports = function(GedcomX){ |
||
5 | |||
6 | // Extend serialization properties |
||
7 | GedcomX.SourceDescription.jsonProps.push('titleLabel', 'sortKey', 'descriptorRef'); |
||
8 | |||
9 | // Override init() |
||
10 | var oldSourceDescriptionInit = GedcomX.SourceDescription.prototype.init; |
||
11 | GedcomX.SourceDescription.prototype.init = function(json){ |
||
12 | oldSourceDescriptionInit.call(this, json); |
||
13 | if(json){ |
||
14 | this.setTitleLabel(json.titleLabel); |
||
15 | this.setSortKey(json.sortKey); |
||
16 | this.setDescriptorRef(json.descriptorRef); |
||
17 | } |
||
18 | }; |
||
19 | |||
20 | /** |
||
21 | * Set the title label |
||
22 | * |
||
23 | * @param {String} titleLabel |
||
24 | * @return {SourceDescription} this |
||
25 | */ |
||
26 | GedcomX.SourceDescription.prototype.setTitleLabel = function(titleLabel){ |
||
27 | this.titleLabel = titleLabel; |
||
28 | return this; |
||
29 | }; |
||
30 | |||
31 | /** |
||
32 | * Get the title label |
||
33 | * |
||
34 | * @return {String} titleLabel |
||
35 | */ |
||
36 | GedcomX.SourceDescription.prototype.getTitleLabel = function(){ |
||
37 | return this.titleLabel; |
||
38 | }; |
||
39 | |||
40 | /** |
||
41 | * Set the sort key |
||
42 | * |
||
43 | * @param {String} sortKey |
||
44 | * @return {SourceDescription} this |
||
45 | */ |
||
46 | GedcomX.SourceDescription.prototype.setSortKey = function(sortKey){ |
||
47 | this.sortKey = sortKey; |
||
48 | return this; |
||
49 | }; |
||
50 | |||
51 | /** |
||
52 | * Get the sort key |
||
53 | * |
||
54 | * @return {String} sortKey |
||
55 | */ |
||
56 | GedcomX.SourceDescription.prototype.getSortKey = function(){ |
||
57 | return this.sortKey; |
||
58 | }; |
||
59 | |||
60 | /** |
||
61 | * Set the descriptor ref |
||
62 | * |
||
63 | * @param {String} descriptorRef |
||
64 | * @return {SourceDescription} this |
||
65 | */ |
||
66 | GedcomX.SourceDescription.prototype.setDescriptorRef = function(descriptorRef){ |
||
67 | this.descriptorRef = descriptorRef; |
||
68 | return this; |
||
69 | }; |
||
70 | |||
71 | /** |
||
72 | * Get the descriptor ref |
||
73 | * |
||
74 | * @return {String} |
||
75 | */ |
||
76 | GedcomX.SourceDescription.prototype.getDescriptorRef = function(){ |
||
77 | return this.descriptorRef; |
||
78 | }; |
||
79 | |||
80 | }; |