Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: copy writable prototype props #88

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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