Skip to content

Instantly share code, notes, and snippets.

@weirhp
Created January 29, 2013 09:47
Show Gist options
  • Save weirhp/4663091 to your computer and use it in GitHub Desktop.
Save weirhp/4663091 to your computer and use it in GitHub Desktop.
js对象复制
/**
* 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