@parrotjs/merge-descriptor
v2.4.0
Published
a util package that you can merge object to the other object
Downloads
19
Readme
一个包可以将多个或者一个对象的属性描述符合并到一个对象里面
一、支持环境
支持node环境和浏览器环境
二、node环境使用 (已通过测试√)
npm install --save @parrotjs/merge-descriptor //安装npm包
//index.js
const merge = require('@parrotjs/merge-descriptor');
let obj1= { a: 'a' };
let obj2 = { b: 'b',c:'c' };
let obj3 = { d: 'd',e:'e',f:'f' };
merge(obj1,obj2,obj3);
console.log("---obj1---",obj1);
//---obj1--- { a: 'a', b: 'b', c: 'c', d: 'd', e: 'e', f: 'f' }
Object.defineProperty(obj2,'c',{enumerable:false})
Object.defineProperty(obj3,'f',{enumerable:false})
merge(obj1,obj2,obj3);
console.log("---obj2---",obj1);
//---obj1--- { a: 'a', b: 'b', d: 'd', e: 'e' }
三、浏览器环境使用
1.HTML中使用 (已通过测试√)
//使用upk在线cdn
https://unpkg.com/@parrotjs/[email protected]/index.js
//使用jsdelivr在线cdn
https://cdn.jsdelivr.net/npm/@parrotjs/[email protected]/index.js
//index.html
<!DOCTYPE html>
<html>
<head>Test</head>
<body>
<script src="https://unpkg.com/@parrotjs/[email protected]/index.js"></script>
<script>
let obj1 = { a: 'a' };
let obj2 = { b: 'b', c: 'c' };
let obj3 = { d: 'd', e: 'e', f: 'f' };
mergeDescriptor(obj1, obj2, obj3);
console.log("---obj1---");
for(let o in obj1){
console.log(o)
}
//---obj1--- a, b, c, d, e, f
Object.defineProperty(obj2, 'c', { enumerable: false })
Object.defineProperty(obj3, 'f', { enumerable: false })
mergeDescriptor(obj1, obj2, obj3);
console.log("---obj2---");
for(let o in obj1){
console.log(o)
}
//---obj1--- a, b, d, e
</script>
</body>
</html>
2.ESM中使用(已通过测试√)
import merge from '@parrotjs/merge-descriptor'
//index.js
let obj1 = { a: 'a' };
let obj2 = { b: 'b', c: 'c' };
let obj3 = { d: 'd', e: 'e', f: 'f' };
mergeDescriptor(obj1, obj2, obj3);
console.log("---obj1---");
for(let o in obj1){
console.log(o)
}
//---obj1--- a, b, c, d, e, f
Object.defineProperty(obj2, 'c', { enumerable: false })
Object.defineProperty(obj3, 'f', { enumerable: false })
mergeDescriptor(obj1, obj2, obj3);
console.log("---obj2---");
for(let o in obj1){
console.log(o)
}
//---obj1--- a, b, d, e
四、github源码地址
https://github.com/parrot-design/parrot-utils/tree/main/merge-descriptor
五、版本变更记录
- 1.0.0 初始化目录
- 2.1.0 修改包
- 2.2.0 修改包
- 2.4.0 修改md文件