Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Use source object prototype in object copy #7846

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ function copy(source, destination, stackSource, stackDest) {
} else if (isRegExp(source)) {
destination = new RegExp(source.source);
} else if (isObject(source)) {
destination = copy(source, {}, stackSource, stackDest);
destination = copy(source, Object.create(Object.getPrototypeOf(source)), stackSource, stackDest);
}
}
} else {
Expand Down
9 changes: 9 additions & 0 deletions test/AngularSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ describe('angular', function() {
expect(aCopy).toBe(aCopy.self);
expect(aCopy.selfs[2]).not.toBe(a.selfs[2]);
});

it('should retain the source prototype on the destination', function () {
function A() {}
var a = new A();
var a_copy = copy(a);

expect(a instanceof A).toBe(true);
expect(a_copy instanceof A).toBe(true);
});
});

describe("extend", function() {
Expand Down