Skip to content

Instantly share code, notes, and snippets.

View danielRicaud's full-sized avatar

Daniel Ricaud danielRicaud

  • Austin, TX
  • 16:18 (UTC -05:00)
View GitHub Profile
@sstur
sstur / clone.js
Created November 21, 2013 06:31
Deep-copy an object, similar to calling JSON.parse(JSON.stringify(obj)) but preserves dates and undefined
function clone(obj) {
if (Object(obj) !== obj) return obj;
if (typeof obj.toJSON == 'function') {
return obj.toJSON();
}
var type = toString.call(obj).slice(8, -1);
if (type in CLONE) {
return CLONE[type].call(obj, clone);
}
var copy = {};