fast-clone.js
v1.1.0
Published
- example with esm ```js import { shallowClone, deepClone, deepClonePro } from "fast-clone.js";
Downloads
7
Maintainers
Readme
fast-clone.js (under MIT licenses)
make shallow or deep clone easy and fast
support cjs, esm, umd
thanks to lodash...etc
- example with esm
import { shallowClone, deepClone, deepClonePro } from "fast-clone.js";
// 复杂对象
let obj = {
num: 0,
str: '',
boolean: true,
unf: undefined,
nul: null,
obj: { name: '我是一个对象', id: 1 },
arr: [0, 1, 2],
func: function () { console.log('我是一个函数') },
date: new Date(0),
reg: new RegExp('/我是一个正则/ig'),
[Symbol('1')]: 1,
};
Object.defineProperty(obj, 'innumerable', {
enumerable: false, value: '不可枚举属性' }
);
obj = Object.create(obj, Object.getOwnPropertyDescriptors(obj))
obj.loop = obj // 设置loop成循环引用的属性
// for shallow clone
let shallowCloneObj = shallowClone(obj);
console.log(shallowCloneObj.obj === obj.obj); // true
// for deep clone, deepClone or deepClonePro are ok, but later is more pro (from lodash)
let deepCloneObj = deepClone(obj);
console.log(deepCloneObj.obj === obj.obj); // false