src code

class method Object.clone

Object.clone(object) → Object
  • object (Object) – The object to clone.

Creates and returns a shallow duplicate of the passed object by copying all of the original's key/value pairs onto an empty object.

Do note that this is a shallow copy, not a deep copy. Nested objects will retain their references.

Examples
var original = {name: 'primaryColors', values: ['red', 'green', 'blue']};
var copy = Object.clone(original);
 original.name;
// -> "primaryColors"
original.values[0];
// -> "red"
copy.name;
// -> "primaryColors"
 copy.name = "secondaryColors";
original.name;
// -> "primaryColors"
copy.name;
// -> "secondaryColors"
 copy.values[0] = 'magenta';
copy.values[1] = 'cyan';
copy.values[2] = 'yellow';
original.values[0];
// -> "magenta" (it's a shallow copy, so they share the array)