Skip to content

Instantly share code, notes, and snippets.

@KrystianP
Last active April 26, 2024 04:39

Revisions

  1. KrystianP revised this gist Sep 24, 2013. No changes.
  2. KrystianP revised this gist Jul 23, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion JS: cloneObject
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    function clone(obj) {
    if (null == obj || "object" != typeof obj) return obj;
    var copy = obj.constructor();
    var copy = new obj.constructor();
    for (var attr in obj) {
    if (obj.hasOwnProperty(attr)) copy[attr] = obj[attr];
    }
  3. KrystianP renamed this gist Jul 23, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. KrystianP created this gist Jul 23, 2013.
    8 changes: 8 additions & 0 deletions js_cloneObject
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    function clone(obj) {
    if (null == obj || "object" != typeof obj) return obj;
    var copy = obj.constructor();
    for (var attr in obj) {
    if (obj.hasOwnProperty(attr)) copy[attr] = obj[attr];
    }
    return copy;
    }