Posted By

carlskov on 10/24/11


Tagged


Versions (?)

Copy an object by value


 / Published in: JavaScript
 

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

  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. };

Report this snippet  

You need to login to post a comment.