Possible Duplicate:
How to clone js object?
This is another way to create a javascript object (using object literal notation instead of function):
user = {
name: "Foo",
email: "bar@baz.com"
}
Is there a way to clone this object or is it a singleton?
Try this:
Here’s what’s going on.
__proto__.The cloned object will share all the properties of the original object without any copies of anything being made. If properties of the cloned object are assigned new values, they won’t interfere with the original object. And no tampering of built-ins is required.
Keep in mind that an object property of the newly-created object will refer to the same object as the eponymous property of the cloned object. Assigning a new value to a property of the clone won’t interfere with the original, but assigning values to the clone’s object properties will.
Try this in chrome or firebug console:
A detailed explanation of this cloning technique can be found here.