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
/** * 浅拷贝 * * @param {*} obj */ var shallowCopy = function (obj) { if (typeof obj != 'object') return; var newObj = obj instanceof Array ? [] : {}; for (var key in obj) { if (obj.hasOwnProperty(key)) { newObj[key] = obj[key] } } return newObj; } /** * 深拷贝 * * @param {*} obj */ var deepCopy = function (obj) { if (typeof obj != 'object') return; var newObj = obj instanceof Array ? [] : {}; for (var key in obj) { if (obj.hasOwnProperty(key)) { newObj[key] = typeof obj[key] == 'object' ? deepCopy(obj[key]) : obj[key]; } } return newObj; }
The text was updated successfully, but these errors were encountered:
这个深拷贝有问题吧,只处理了数组,其他类对象就有问题了,可以试下这个对象
var obj = { a: 1, b: '2', c: { cc: 2 }, d: function (a) { console.log(a) }, e: [1, 2, 3, 4, 5], f: undefined, g: null, h: Symbol('123'), i: { aa: 11, bb: '22', cc: { ccc: { cccc: function (a) { console.log(a) } } } }, j: new Date() }
Sorry, something went wrong.
这个深拷贝有问题吧,只处理了数组,其他类对象就有问题了,可以试下这个对象 var obj = { a: 1, b: '2', c: { cc: 2 }, d: function (a) { console.log(a) }, e: [1, 2, 3, 4, 5], f: undefined, g: null, h: Symbol('123'), i: { aa: 11, bb: '22', cc: { ccc: { cccc: function (a) { console.log(a) } } } }, j: new Date() }
这个是不支持的哈~ 只处理了数组和普通的对象~
No branches or pull requests
The text was updated successfully, but these errors were encountered: