Create a clone of an object.

While there are various ways to clone an object, this one is extremely consistent and also performs well on jsperf tests. However, please note that this technique with "plain objects" (ones that inherit directly from Object.prototype). See the comments for further discussion.

function clone(obj) {
    return JSON.parse(JSON.stringify(obj));
}

Author: Don Burks
Tags: object

comments powered by Disqus