主题
defaults
js
_.defaults(object, [sources])
对于所有解析为 undefined
的目标属性,将源对象的自身和继承的可枚举字符串键属性分配给目标对象。源对象从左到右应用。设置属性后,将忽略同一属性的其他值。
¥Assigns own and inherited enumerable string keyed properties of source objects to the destination object for all destination properties that resolve to undefined
. Source objects are applied from left to right. Once a property is set, additional values of the same property are ignored.
注意:此方法改变 object
。
¥Note: This method mutates object
.
新增于
¥Since
0.1.0
参数
¥Arguments
object
(对象):目标对象。¥
object
(Object): The destination object.[sources]
(...对象):起始位置。¥
[sources]
(...Object): The source objects.
返回
¥Returns
(对象):返回 object
。
¥(Object): Returns object
.
示例
¥Example
js
_.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
// => { 'a': 1, 'b': 2 }