MCPcopy
hub / github.com/ygs-code/vue / mergeData

Function mergeData

vue.js:1717–1735  ·  view source on GitHub ↗

* Helper that recursively merges two data objects together. * 递归合并数据 深度拷贝

(to, from)

Source from the content-addressed store, hash-verified

1715 * 递归合并数据 深度拷贝
1716 */
1717 function mergeData(to, from) {
1718 if (!from) {
1719 return to
1720 }
1721 var key, toVal, fromVal;
1722 var keys = Object.keys(from); //获取对象的keys 变成数组
1723 for (var i = 0; i < keys.length; i++) {
1724 key = keys[i]; //获取对象的key
1725 toVal = to[key]; //
1726 fromVal = from[key]; //获取对象的值
1727 if (!hasOwn(to, key)) { //如果from对象的key在to对象中没有
1728 set(to, key, fromVal);
1729 } else if (isPlainObject(toVal) && isPlainObject(fromVal)) {
1730 //深层递归
1731 mergeData(toVal, fromVal);
1732 }
1733 }
1734 return to
1735 }
1736
1737 /**
1738 * Data

Callers 1

mergeDataOrFnFunction · 0.85

Calls 3

hasOwnFunction · 0.85
setFunction · 0.85
isPlainObjectFunction · 0.85

Tested by

no test coverage detected