Created
January 29, 2013 09:47
-
-
Save weirhp/4663091 to your computer and use it in GitHub Desktop.
js对象复制
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
/** | |
* js对象复制 | |
*/ | |
function cloneObject(source) { | |
if (typeof source !== "object") { | |
return source; | |
} | |
var s = {}; | |
if ($.isArray(source)) { | |
s = []; | |
} | |
for ( var key in source) { | |
if (key.substr(0, 6) == 'jQuery') { | |
continue; | |
} | |
s[key] = this.cloneObject(source[key]); | |
} | |
return s; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment