- Source:
Shallowly clone an object.
const {Shallowclone, shallowclone} = require('ferrum');
class Bar {
constructor(foo, bang) {
this.foo = foo;
this.bang = bang;
}
[Shallowclone.sym]() {
return new Bar(this.foo, this.bar);
}
}
const a = new Bar({foo: 42}, {bar: 5});
const b = shallowclone(a);
assert(a !== b);
assertEquals(a, b);
a.foo.foo = 5;
assert(b.foo.foo === 5);
Interface
(x: TheValue) => r: TheValue
Laws
x !== rget(r, k) === get(x, k)for any k.
Implementation Notes
No-Op implementations are provided for read only primitive types.
See: shallowclone