All files / obj clone.js

100% Statements 2/2
100% Branches 0/0
100% Functions 1/1
100% Lines 2/2

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17                        4x     1x  
/**
 * 简易克隆对象,会丢失函数等不能被 JSON 序列化的内容
 * @method obj/clone
 * @param {Object} object 要克隆的对象
 * @returns {Object} 克隆后的对象
 * @example
 * var $clone = require('@spore-ui/kit/packages/obj/clone');
 * var obj = {a: 1, b: 2};
 * console.info($clone(obj)); //{a: 1, b: 2}
 */
 
function clone(obj) {
  return JSON.parse(JSON.stringify(obj));
}
 
module.exports = clone;