codecamp

Lodash _.mergeWith

_.mergeWith(object, sources, customizer)

该方法类似_.merge,除了它接受一个 customizer,调用以产生目标对象和来源对象属性的合并值。如果customizer 返回 undefined,将会由合并处理方法代替。customizer调用与7个参数:(objValue, srcValue, key, object, source, stack)。Note: 这方法会改变对象 object.

添加版本

4.0.0

参数

  1. object (Object): 目标对象。
  2. [sources] (...Object): 来源对象。
  3. customizer (Function): 这个函数定制合并值。

返回

(Object): 返回 object。

例子

function customizer(objValue, srcValue) {  if (_.isArray(objValue)) {    return objValue.concat(srcValue);  }} 
var object = { 'a': [1], 'b': [2] };
var other = { 'a': [3], 'b': [4] };
 _.mergeWith(object, other, customizer);
// => { 'a': [1, 3], 'b': [2, 4] }


Lodash _.merge
Lodash _.omit
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

Lodash 简介

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }