Conditions | 1 |
Paths | 1 |
Total Lines | 59 |
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 | var assert = require('chai').assert, |
||
40 | describe('merge', function(){ |
||
41 | |||
42 | it('objects', function(){ |
||
43 | var dest = {}, |
||
44 | merged = utils.merge( |
||
45 | dest, |
||
46 | { |
||
47 | a: 1, |
||
48 | b: { |
||
49 | b1: 'foo' |
||
50 | } |
||
51 | }, |
||
52 | { |
||
53 | a: 2, |
||
54 | b: { |
||
55 | b2: 'bar' |
||
56 | } |
||
57 | } |
||
58 | ); |
||
59 | assert.strictEqual(dest, merged); |
||
60 | assert.deepEqual( |
||
61 | dest, |
||
62 | { |
||
63 | a: 2, |
||
64 | b: { |
||
65 | b1: 'foo', |
||
66 | b2: 'bar' |
||
67 | } |
||
68 | } |
||
69 | ); |
||
70 | }); |
||
71 | |||
72 | it('arrays', function(){ |
||
73 | var dest = {}, |
||
74 | merged = utils.merge( |
||
75 | dest, |
||
76 | { |
||
77 | facts: [ |
||
78 | { |
||
79 | date: { |
||
80 | formal: '+2001' |
||
81 | } |
||
82 | } |
||
83 | ] |
||
84 | } |
||
85 | ); |
||
86 | assert.strictEqual(dest, merged); |
||
87 | assert.deepEqual(dest, { |
||
88 | facts: [ |
||
89 | { |
||
90 | date: { |
||
91 | formal: '+2001' |
||
92 | } |
||
93 | } |
||
94 | ] |
||
95 | }); |
||
96 | }); |
||
97 | |||
98 | }); |
||
99 | |||
127 | }); |