Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Clone obj in js
function clone(obj) {
if (null == obj || "object" != typeof obj) return obj;
var copy = new obj.constructor();
for (var attr in obj) {
if (obj.hasOwnProperty(attr)) copy[attr] = obj[attr];
return copy;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.