From b67b0159ec8b19858dd2b375786998753ee8ec5b Mon Sep 17 00:00:00 2001 From: Paul Jolly Date: Mon, 16 Jun 2014 12:05:25 +0100 Subject: [PATCH 1/2] Use source object prototype in object copy --- src/Angular.js | 2 +- test/AngularSpec.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Angular.js b/src/Angular.js index 905421e0fd03..5da0e1e4498b 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -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 { diff --git a/test/AngularSpec.js b/test/AngularSpec.js index 472ae6269913..9fc3d2758369 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -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() { From 4c18a7e22c819dacf7bb91b0e9f83e10cff9caf4 Mon Sep 17 00:00:00 2001 From: Paul Jolly Date: Mon, 16 Jun 2014 12:06:56 +0100 Subject: [PATCH 2/2] Remove unneccessary semi-colon --- test/AngularSpec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/AngularSpec.js b/test/AngularSpec.js index 9fc3d2758369..cfeef7988c12 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -162,7 +162,7 @@ describe('angular', function() { }); it('should retain the source prototype on the destination', function () { - function A() {}; + function A() {} var a = new A(); var a_copy = copy(a);