Bakhtina Sofya b84cb877be 1st comm | 2 周之前 | |
---|---|---|
.. | ||
LICENSE | 2 周之前 | |
README.md | 2 周之前 | |
bower.json | 2 周之前 | |
merge.js | 2 周之前 | |
merge.min.js | 2 周之前 | |
package.json | 2 周之前 |
Merge multiple objects into one, optionally creating a new cloned object. Similar to the jQuery.extend but more flexible. Works in Node.js and the browser.
npm install merge --save
var merge = require('merge'), original, cloned;
console.log(merge({one:'hello'}, {two: 'world'}));
// -> {"one": "hello", "two": "world"}
original = { x: { y: 1 } };
cloned = merge(true, original);
cloned.x.y++;
console.log(original.x.y, cloned.x.y);
// -> 1, 2
console.log(merge.recursive(true, original, { x: { z: 2 } }));
// -> {"x": { "y": 1, "z": 2 } }
<script src="https://cdn.jsdelivr.net/gh/yeikos/js.merge/merge.js"></script>
<script>
var original, cloned;
console.log(merge({one:'hello'}, {two: 'world'}));
// -> {"one": "hello", "two": "world"}
original = { x: { y: 1 } };
cloned = merge(true, original);
cloned.x.y++;
console.log(original.x.y, cloned.x.y);
// -> 1, 2
console.log(merge.recursive(true, original, { x: { z: 2 } }));
// -> {"x": { "y": 1, "z": 2 } }
</script>
npm test