Skip to content

Conversation

@vkarpov15
Copy link

Hi,

Looks like #36 introduced a bug where prototype properties that don't have a setter won't get copied, even if they are writable. Example:

function X() {
  this.test = 'A';
}

Object.defineProperty(X.prototype, 'test', {
  configurable: false,
  writable: true,
  enumerable: true
});

// "X { test: 'A' }"
console.log(new X());
// "X {}", `test` prop omitted!
console.log(clone(new X()));

This issue came up in Automattic/mongoose#5896

Thanks for the great lib and happy holidays!

@olsonpm
Copy link

olsonpm commented Apr 17, 2018

Just in case it's not clear, mdn defines descriptors as either being "data" or "accessor" descriptors. The current code assumes only the latter whereas both need to be accounted for.

A data descriptor also has the following optional keys:
value... writeable

An accessor descriptor also has the following optional keys:
get... set

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants