Skip to content

Non enumerable properties #8

@felipe-gustavo

Description

@felipe-gustavo

deepClony doen't works with non enumerable properties, such below e.g.:

class e {
  id;
  data;
  constructor(data) {
    this.id = Math.floor(Math.random() * 25);
    this.data = data;
    Object.defineProperty(this, "gTr", {
      enumerable: false,
      value: function () {
        return "it's me! " + this.id;
      }
    });
  }
}

const i = new e({ a: 1, b: 2 });
const u = Object.assign(
  Object.create(i),
  Object.getPrototypeOf(Object.create(i))
);
const o = deepCopy(i);

u.id = 28;
u.data.a = 3;
o.data.a = 4;

console.log(
  "i:",
  i.gTr && i.gTr(),
  i.data.a,
  "o:",
  o.gTr && o.gTr(),
  o.data.a,
  "u:",
  u.gTr && u.gTr(),
  u.data.a
);

output:

i:
   it's me! 23 
   3
o: 
   undefined
   4
u:
   it's me! 28 
   3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions