Last active
December 19, 2015 21:58
-
-
Save imalberto/6023748 to your computer and use it in GitHub Desktop.
util.common.js#copy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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