Return to Snippet

Revision: 52472
at October 24, 2011 19:30 by carlskov


Initial Code
Object.prototype.clone = function() {
  var newObj = (this instanceof Array) ? [] : {};
  for (i in this) {
    if (i == 'clone') continue;
    if (this[i] && typeof this[i] == "object") {
      newObj[i] = this[i].clone();
    } else newObj[i] = this[i]
  } return newObj;
};

Initial URL
http://my.opera.com/GreyWyvern/blog/show.dml/1725165

Initial Description


Initial Title
Copy an object by value

Initial Tags


Initial Language
JavaScript