Creates a shallow clone of an object.
Use Object.assign()
and an empty object ({}
) to create a shallow clone of the original.
代码片段
const shallowClone = obj => Object.assign({}, obj);
使用样例
const a = { x: true, y: 1 };
const b = shallowClone(a); // a !== b