Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorder util.extend logic, fixing dead code #152

Merged
merged 1 commit into from
Aug 29, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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