Skip to content

Instantly share code, notes, and snippets.

@mrsid96
Created April 3, 2019 03:11
Show Gist options
  • Save mrsid96/07b4b1a9cde067b0aa8cc81fe6c26f5d to your computer and use it in GitHub Desktop.
Save mrsid96/07b4b1a9cde067b0aa8cc81fe6c26f5d to your computer and use it in GitHub Desktop.
Cloning the object using Prototyping
var clone = function (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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment