diff --git a/src/helpers/helpers.core.js b/src/helpers/helpers.core.js index 350a2075091..6cf28c00d41 100644 --- a/src/helpers/helpers.core.js +++ b/src/helpers/helpers.core.js @@ -175,7 +175,7 @@ var helpers = { } if (helpers.isObject(source)) { - var target = {}; + var target = Object.create(source); var keys = Object.keys(source); var klen = keys.length; var k = 0; diff --git a/test/specs/helpers.core.tests.js b/test/specs/helpers.core.tests.js index cdda01b9674..1f524089a21 100644 --- a/test/specs/helpers.core.tests.js +++ b/test/specs/helpers.core.tests.js @@ -301,6 +301,25 @@ describe('Chart.helpers.core', function() { expect(output.o.a).not.toBe(a1); expect(output.a).not.toBe(a0); }); + it('should preserve prototype of objects', function() { + // https://github.com/chartjs/Chart.js/issues/7340 + function MyConfigObject(s) { + this._s = s; + } + MyConfigObject.prototype.func = function() { + return 10; + }; + var original = new MyConfigObject('something'); + var output = helpers.merge({}, { + plugins: [{ + test: original + }] + }); + var clone = output.plugins[0].test; + expect(clone).toBeInstanceOf(MyConfigObject); + expect(clone).toEqual(original); + expect(clone === original).toBeFalse(); + }); }); describe('merge', function() {