function shallowClone(obj) {
var clone = Object.create(Object.getPrototypeOf(obj));
var props = Object.getOwnPropertyNames(obj);
props.forEach(function(key) {
var desc = Object.getOwnPropertyDescriptor(obj, key);
Object.defineProperty(clone, key, desc);
});
return clone;
}
In ES2017function shallowClone(obj) {
return Object.create(
Object.getPrototypeOf(obj),
Object.getOwnPropertyDescriptors(obj)
);
}