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

Copying Function.prototype #15

Closed
ehmicky opened this issue Mar 15, 2019 · 3 comments · Fixed by #28
Closed

Copying Function.prototype #15

ehmicky opened this issue Mar 15, 2019 · 3 comments · Fixed by #28

Comments

@ehmicky
Copy link
Collaborator

ehmicky commented Mar 15, 2019

Behavior is different depending on whether the function to mimic is an arrow function or not:

const from = function() {}
const to = function() {}
console.log(from.prototype === to.prototype) // false
mimicFn(from, to)
console.log(from.prototype === to.prototype) // true
const from = function() {}
const to = () => {}
console.log(from.prototype === to.prototype) // false
mimicFn(from, to)
console.log(from.prototype === to.prototype) // false

This is because Function.prototype is not defined for arrow functions. mimic-fn only iterates over properties that are defined.

This leaves two questions:

  • when from.prototype is not defined, should to.prototype be deleted?
  • when any property is defined in to but not from, should it be deleted from to?
@sindresorhus
Copy link
Owner

when from.prototype is not defined, should to.prototype be deleted?

Yes

when any property is defined in to but not from, should it be deleted from to?

Yes, but it should be clearly documented.

@ehmicky
Copy link
Collaborator Author

ehmicky commented May 1, 2019

I will submit a PR for this after #18 is merged (to avoid conflicts).

@ehmicky
Copy link
Collaborator Author

ehmicky commented Jun 11, 2019

PR at #28

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

Successfully merging a pull request may close this issue.

2 participants