From d524d10bb72686526307f4d79608634aea31113e Mon Sep 17 00:00:00 2001 From: Piotr Kaminski Date: Mon, 3 Oct 2016 23:30:08 -0700 Subject: [PATCH] Fix conflated prototype chains when extending. --- src/core.js | 2 +- test/lib-base-test.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/core.js b/src/core.js index 22711eb..c318ca7 100644 --- a/src/core.js +++ b/src/core.js @@ -48,7 +48,7 @@ var CryptoJS = CryptoJS || (function (Math, undefined) { } // Create default initializer - if (!subtype.hasOwnProperty('init')) { + if (!subtype.hasOwnProperty('init') || this.init === subtype.init) { subtype.init = function () { subtype.$super.init.apply(this, arguments); }; diff --git a/test/lib-base-test.js b/test/lib-base-test.js index 8d3c715..ed8e642 100644 --- a/test/lib-base-test.js +++ b/test/lib-base-test.js @@ -81,6 +81,12 @@ YUI.add('lib-base-test', function (Y) { this.data.obj.initArg = 'newValue'; Y.Assert.areNotEqual(this.data.obj.initArg, this.data.objClone.initArg); + }, + + testCloneLeavesOriginalInitPrototypeUnchanged: function() { + Y.Assert.areEqual(this.data.obj, this.data.obj.init.prototype); + Y.Assert.areEqual(this.data.objClone, this.data.objClone.init.prototype); + Y.Assert.areNotEqual(this.data.obj.init.prototype, this.data.objClone.init.prototype); } })); }, '$Rev$');