diff --git a/clone.js b/clone.js index 80d0c76..441f64e 100644 --- a/clone.js +++ b/clone.js @@ -150,7 +150,9 @@ function clone(parent, circular, depth, prototype, includeNonEnumerable) { attrs = Object.getOwnPropertyDescriptor(proto, i); } - if (attrs && attrs.set == null) { + // If attribute is not writable and doesn't have a setter, skip it + // Re: https://github.com/pvorb/clone/pull/36 + if (attrs && attrs.set == null && !attrs.writable) { continue; } child[i] = _clone(parent[i], depth - 1); diff --git a/test.js b/test.js index fb4ba67..f1d935a 100644 --- a/test.js +++ b/test.js @@ -333,6 +333,24 @@ exports['clone instance with getter'] = function (test) { test.done(); }; +exports['clone writable prototype prop'] = function (test) { + test.expect(1); + function Ctor() { + this.prop = 'value'; + } + Object.defineProperty(Ctor.prototype, 'prop', { + configurable: true, + enumerable: true, + writable: true + }); + + var a = new Ctor(); + var b = clone(a); + + test.strictEqual(b.prop, 'value'); + test.done(); +}; + if (Object.getOwnPropertySymbols) { exports['clone object with symbol properties'] = function (test) { var symbol = Symbol();