Skip to content

Commit

Permalink
Reorder util.extend logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanseys committed Aug 29, 2014
1 parent 6fd7154 commit 346df2e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/common/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ function extend(from, to) {
if (from === null || typeof from !== 'object') {
return from;
}
if (from.constructor !== Object && from.constructor !== Array) {
return from;
}
if (from.constructor === Date || from.constructor === Function ||
from.constructor === String || from.constructor === Number ||
from.constructor === Boolean) {
return new from.constructor(from);
}
if (from.constructor !== Object && from.constructor !== Array) {
return from;
}
to = to || new from.constructor();
for (var name in from) {
to[name] = to[name] ? extend(from[name], null) : to[name];
Expand Down
7 changes: 7 additions & 0 deletions test/common/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ describe('extend', function() {
var copy = util.extend(null, {});
assert.strictEqual(copy, null);
});

it('should return a new Date for Date input', function() {
var now = new Date();
var copy = util.extend(now, {});
assert.notStrictEqual(copy, now);
assert.strictEqual(copy.toString(), now.toString());
});
});

describe('arrayize', function() {
Expand Down

0 comments on commit 346df2e

Please sign in to comment.