Skip to content

Commit 7e7c41f

Browse files
author
Burcu Dogan
committed
Merge pull request #152 from ryanseys/fix-extend
Reorder util.extend logic, fixing dead code
2 parents c5a004e + 346df2e commit 7e7c41f

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/common/util.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ function extend(from, to) {
3535
if (from === null || typeof from !== 'object') {
3636
return from;
3737
}
38-
if (from.constructor !== Object && from.constructor !== Array) {
39-
return from;
40-
}
4138
if (from.constructor === Date || from.constructor === Function ||
4239
from.constructor === String || from.constructor === Number ||
4340
from.constructor === Boolean) {
4441
return new from.constructor(from);
4542
}
43+
if (from.constructor !== Object && from.constructor !== Array) {
44+
return from;
45+
}
4646
to = to || new from.constructor();
4747
for (var name in from) {
4848
to[name] = to[name] ? extend(from[name], null) : to[name];

test/common/util.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ describe('extend', function() {
2626
var copy = util.extend(null, {});
2727
assert.strictEqual(copy, null);
2828
});
29+
30+
it('should return a new Date for Date input', function() {
31+
var now = new Date();
32+
var copy = util.extend(now, {});
33+
assert.notStrictEqual(copy, now);
34+
assert.strictEqual(copy.toString(), now.toString());
35+
});
2936
});
3037

3138
describe('arrayize', function() {

0 commit comments

Comments
 (0)