我正在寻找一个功能,如果它存在,则覆盖一个对象的值与另一个对象的值,但我没有在lodash
文档中找到它
var primary = {
name: 'egg'
weight: '2oz',
meal: 'breakfast'
}
var secondary = {
name: 'egg',
weight: '3oz'
state: 'uncracked'
}
var result = _.override(primary, secondary);
console.log(result)
// => { name: 'egg' weight: '3oz', meal: 'breakfast, state: 'uncracked' }
如何在函数式编程中实现这一目标?
答案 0 :(得分:5)
结帐Lodash的Note: This method mutates object and is loosely based on Object.assign.
功能 - https://lodash.com/docs/4.17.2#assign。
var primary = {
name: 'egg',
weight: '2oz',
meal: 'breakfast'
};
var secondary = {
name: 'egg',
weight: '3oz',
state: 'uncracked'
};
var result = _.assign({}, primary, secondary);
console.log(result)
// => { name: 'egg' weight: '3oz', meal: 'breakfast, state: 'uncracked' }
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.js"></script></script>
&#13;
@for (int i = 1; i <= 10; i++)
{
@i
}
&#13;