/** * @description 浅、深拷贝对象数组 * @param {object} target - 目标对象、数组 * @param {object} options - 被拷贝对象、数组 * @param {boolean} deep - 是否深拷贝 * @returns {object} target */ function extend(target, options, deep) { for (const key in options) { if (Object.prototype.hasOwnProperty.call(options, key)) { const copy = options[key]; if (deep && copy instanceof Array) { target[key] = extend([], copy, deep); } else if (deep && copy instanceof Object) { target[key] = extend({}, copy, deep); } else { target[key] = options[key]; } } } return target; }
浅、深拷贝对象数组
最新推荐文章于 2024-05-03 11:08:18 发布