* @memberOf module:zrender/core/util * @param {*} target * @param {*} source * @param {boolean} [overwrite=false]
(target, source, overwrite)
| 355 | * @param {boolean} [overwrite=false] |
| 356 | */ |
| 357 | function merge(target, source, overwrite) { |
| 358 | // We should escapse that source is string |
| 359 | // and enter for ... in ... |
| 360 | if (!isObject$1(source) || !isObject$1(target)) { |
| 361 | return overwrite ? clone(source) : target; |
| 362 | } |
| 363 | |
| 364 | for (var key in source) { |
| 365 | if (source.hasOwnProperty(key)) { |
| 366 | var targetProp = target[key]; |
| 367 | var sourceProp = source[key]; |
| 368 | |
| 369 | if (isObject$1(sourceProp) |
| 370 | && isObject$1(targetProp) |
| 371 | && !isArray(sourceProp) |
| 372 | && !isArray(targetProp) |
| 373 | && !isDom(sourceProp) |
| 374 | && !isDom(targetProp) |
| 375 | && !isBuiltInObject(sourceProp) |
| 376 | && !isBuiltInObject(targetProp) |
| 377 | && !isPrimitive(sourceProp) |
| 378 | && !isPrimitive(targetProp) |
| 379 | ) { |
| 380 | // 如果需要递归覆盖,就递归调用merge |
| 381 | merge(targetProp, sourceProp, overwrite); |
| 382 | } |
| 383 | else if (overwrite || !(key in target)) { |
| 384 | // 否则只处理overwrite为true,或者在目标对象中没有此属性的情况 |
| 385 | // NOTE,在 target[key] 不存在的时候也是直接覆盖 |
| 386 | target[key] = clone(source[key], true); |
| 387 | } |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | return target; |
| 392 | } |
| 393 | |
| 394 | /** |
| 395 | * @param {Array} targetAndSources The first item is target, and the rests are source. |
no test coverage detected