codecamp

Lodash _.extendWith->assignInWith

_.assignInWith(object, sources, [customizer])

这个方法类似_.assignIn, 除了它接受一个 customizer ,被调用以产生所分配的值。 如果 customizer 返回 undefined 将会由分配处理方法代替。 customizer 会传入5个参数: (objValue, srcValue, key, object, source)。Note: 这方法会改变 object。

添加版本

4.0.0

Aliases

_.extendWith

参数

  1. object (Object): 目标对象。
  2. sources (...Object): 来源对象。
  3. [customizer] (Function): 这个函数用来自定义分配的值。

返回

(Object): 返回 object。

例子

function customizer(objValue, srcValue) {  return _.isUndefined(objValue) ? srcValue : objValue;} 
var defaults = _.partialRight(_.assignInWith, customizer); 
defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
// => { 'a': 1, 'b': 2 }


Lodash _.extend->assignIn
Lodash _.findKey
温馨提示
下载编程狮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; }