Shallowclone

stdtraits~ Shallowclone

Source:

Shal­lowly clone an ob­ject.

const {Shal­low­clone, shal­low­clone} = re­quire('fer­rum');

class Bar {
  con­structor(foo, bang) {
    this.foo = foo;
    this.bang = bang;
  }

  [Shal­low­clone.sym]() {
    re­turn new Bar(this.foo, this.bar);
  }
}

const a = new Bar({foo: 42}, {bar: 5});
const b = shal­low­clone(a);

as­sert(a !== b);
as­ser­tEquals(a, b);

a.foo.foo = 5;
as­sert(b.foo.foo === 5);

In­ter­face

(x: The­Value) => r: The­Value

Laws

  • x !== r
  • get(r, k) === get(x, k) for any k.

Im­ple­ment­a­tion Notes

No-Op im­ple­ment­a­tions are provided for read only prim­it­ive types.

See: shal­low­clone