Skip to content

Instantly share code, notes, and snippets.

@imalberto
Last active December 19, 2015 21:58
Show Gist options
  • Save imalberto/6023748 to your computer and use it in GitHub Desktop.
Save imalberto/6023748 to your computer and use it in GitHub Desktop.
util.common.js#copy
copy: function(oldObj) {
var newObj,
key,
len,
type,
copy = Y.mojito.util.copy;
if (!oldObj) {
return oldObj;
}
type = Y.Lang.type(oldObj);
if (typeof oldObj !== 'object' ||
(type === 'regexp' || type === 'function')) {
return oldObj;
}
if (type === "array") {
newObj = [];
len = oldObj.length;
for (key = 0; key < len; key += 1) {
newObj[key] = copy(oldObj[key]);
}
return newObj;
}
newObj = {};
for (key in oldObj) {
if (oldObj.hasOwnProperty(key)) {
newObj[key] = copy(oldObj[key]);
}
}
return newObj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment