We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
function getType(obj) { // 为啥不用typeof? typeof无法区分数组和对象 if(Object.prototype.toString.call(obj) == '[object Object]') { return 'Object'; } if(Object.prototype.toString.call(obj) == '[object Array]') { return 'Array'; } return 'nomal'; }; function deepCopy(obj) { if (getType(obj) == 'nomal') { return obj; } else { var newObj = getType(obj) == 'Object' ? {} : []; for(var key in obj) { // 为啥要用hasOwnProperty?不需要从对象的原型链上进行复制 if(obj.hasOwnProperty(key)) { newObj[key] = deepCopy(obj[key]); } } } return newObj; } var object = [ { title: 'test', checked: false } ]; deepCopy(object);
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The text was updated successfully, but these errors were encountered: