Copy an object by value


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. Object.prototype.clone = function() {
  2. var newObj = (this instanceof Array) ? [] : {};
  3. for (i in this) {
  4. if (i == 'clone') continue;
  5. if (this[i] && typeof this[i] == "object") {
  6. newObj[i] = this[i].clone();
  7. } else newObj[i] = this[i]
  8. } return newObj;
  9. };

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.