Conditions | 1 |
Paths | 2 |
Total Lines | 53 |
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.ExtensibleData.jsonProps.push('fields'); |
||
8 | |||
9 | // Override init() |
||
10 | var oldExtensibleDataInit = GedcomX.ExtensibleData.prototype.init; |
||
11 | GedcomX.ExtensibleData.prototype.init = function(json){ |
||
12 | oldExtensibleDataInit.call(this, json); |
||
13 | if(json){ |
||
14 | this.setFields(json.fields); |
||
15 | } |
||
16 | }; |
||
17 | |||
18 | /** |
||
19 | * Set the fields |
||
20 | * |
||
21 | * @function setFields |
||
22 | * @instance |
||
23 | * @memberof ExtensibleData |
||
24 | * @param {Field[]} fields |
||
25 | * @return {ExtensibleData} this |
||
26 | */ |
||
27 | GedcomX.ExtensibleData.prototype.setFields = function(fields){ |
||
28 | return this._setArray(fields, 'fields', 'addField'); |
||
29 | }; |
||
30 | |||
31 | /** |
||
32 | * Add a field |
||
33 | * |
||
34 | * @function addField |
||
35 | * @instance |
||
36 | * @memberof ExtensibleData |
||
37 | * @param {Field} field |
||
38 | * @return {ExtensibleData} this |
||
39 | */ |
||
40 | GedcomX.ExtensibleData.prototype.addField = function(field){ |
||
41 | return this._arrayPush(field, 'fields', GedcomX.Field); |
||
42 | }; |
||
43 | |||
44 | /** |
||
45 | * Get the fields |
||
46 | * |
||
47 | * @function getFields |
||
48 | * @instance |
||
49 | * @memberof ExtensibleData |
||
50 | * @return {Field[]} |
||
51 | */ |
||
52 | GedcomX.ExtensibleData.prototype.getFields = function(){ |
||
53 | return this.fields || []; |
||
54 | }; |
||
55 | |||
56 | }; |