Skip to content
Open
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
4 changes: 3 additions & 1 deletion clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 18 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down