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

Not cloning object getters and setters as expected #121

Open
bertolo1988 opened this issue Oct 9, 2022 · 2 comments
Open

Not cloning object getters and setters as expected #121

bertolo1988 opened this issue Oct 9, 2022 · 2 comments

Comments

@bertolo1988
Copy link

bertolo1988 commented Oct 9, 2022

The following tests should not fail:

 it('should clone a getter', () => {
   const input = {
     a: 2,
     get foo() {
       return this.a * 2
     }
   }
   let clone = func(input)
   assert.ok(clone.foo === 4)
   assert.ok(
     typeof Object.getOwnPropertyDescriptor(clone, 'foo').get === 'function'
   )
 })
 
 
it('should clone a setter', () => {
   const input = {
     set foo(val) {
       this.a = val
     }
   }
   let clone = func(input)
   clone.foo('bar')
   assert.ok(clone.a === 'bar')
   assert.ok(input.a === undefined)
   assert.ok(
     typeof Object.getOwnPropertyDescriptor(clone, 'foo').set === 'function'
   )
 })
@bertolo1988 bertolo1988 changed the title Not cloning getters and setters as expected Not cloning object getters and setters as expected Oct 9, 2022
@pvorb
Copy link
Owner

pvorb commented Oct 13, 2022

This lib was written back when these methods did not exist (I believe).

I don't have time to actively maintain it. So you might want to look for alternatives that support this.

@jimmywarting
Copy link

could also be worth mentioning that there also is a built in structuredClone() that do also support getters.

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

No branches or pull requests

3 participants