clone.js 236 B

12345678
  1. function clone(obj) {
  2. if (null == obj || "object" != typeof obj) return obj;
  3. var copy = obj.constructor();
  4. for (var attr in obj) {
  5. if (obj.hasOwnProperty(attr)) copy[attr] = clone(obj[attr]);
  6. }
  7. return copy;
  8. }