[javascript] 对象拷贝

 1 Object.prototype.clone = function() {
 2   var copy = (this instanceof Array) ? [] : {};
 3   for (attr in this) {
 4     if (!obj.hasOwnProperty(attr)) continue;
 5     copy[attr] = (typeof this[i] == "object")?obj[attr].clone():obj[attr];
 6   } 
 7   return copy;
 8 };
 9 
10 
11 a = {k1:1, k2:2, k3:3};
12 b = a.clone();
原文地址:https://www.cnblogs.com/bluefrog/p/3469538.html