Conditions | 1 |
Paths | 1 |
Total Lines | 84 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
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.Person.jsonProps.push('living', 'display'); |
||
8 | |||
9 | // Override init() so that we can deserialize normalized values |
||
10 | var oldInit = GedcomX.Person.prototype.init; |
||
11 | GedcomX.Person.prototype.init = function(json){ |
||
12 | oldInit.call(this, json); |
||
13 | if(json){ |
||
14 | this.setLiving(json.living); |
||
15 | this.setDisplay(json.display); |
||
16 | } |
||
17 | }; |
||
18 | |||
19 | /** |
||
20 | * Set the living flag |
||
21 | * |
||
22 | * @function setLiving |
||
23 | * @instance |
||
24 | * @memberof Person |
||
25 | * @param {Boolean} living |
||
26 | * @return {Person} this |
||
27 | */ |
||
28 | GedcomX.Person.prototype.setLiving = function(living){ |
||
29 | this.living = living; |
||
30 | return this; |
||
31 | }; |
||
32 | |||
33 | /** |
||
34 | * Get the living flag |
||
35 | * |
||
36 | * @function getLiving |
||
37 | * @instance |
||
38 | * @memberof Person |
||
39 | * @return {Boolean} living |
||
40 | */ |
||
41 | GedcomX.Person.prototype.getLiving = function(){ |
||
42 | return this.living; |
||
43 | }; |
||
44 | |||
45 | /** |
||
46 | * Set the display properties |
||
47 | * |
||
48 | * @function setDisplay |
||
49 | * @instance |
||
50 | * @memberof Person |
||
51 | * @param {DisplayProperties} display |
||
52 | * @return {Person} this |
||
53 | */ |
||
54 | GedcomX.Person.prototype.setDisplay = function(display){ |
||
55 | if(display){ |
||
56 | this.display = GedcomX.DisplayProperties(display); |
||
57 | } |
||
58 | return this; |
||
59 | }; |
||
60 | |||
61 | /** |
||
62 | * Get the display properties |
||
63 | * |
||
64 | * @function getDisplay |
||
65 | * @instance |
||
66 | * @memberof Person |
||
67 | * @return {DisplayProperties} |
||
68 | */ |
||
69 | GedcomX.Person.prototype.getDisplay = function(){ |
||
70 | return this.display; |
||
71 | }; |
||
72 | |||
73 | /** |
||
74 | * Get a person's preferred name, if one exists. |
||
75 | * |
||
76 | * @function getPreferredName |
||
77 | * @instance |
||
78 | * @memberof Person |
||
79 | * @return {Name} |
||
80 | */ |
||
81 | GedcomX.Person.prototype.getPreferredName = function(){ |
||
82 | return this.getNames().find(function(n){ |
||
83 | return n.getPreferred(); |
||
84 | }); |
||
85 | }; |
||
86 | |||
87 | }; |