【发布时间】:2021-08-03 20:04:31
【问题描述】:
有没有办法获取Underscore.js extend函数:
将源对象中的所有属性复制到 目标对象,并返回目标对象。有条不紊, 所以最后一个源将覆盖同名的属性 以前的论点。
...递归工作?
实际上,creditOperation 中的query 属性将完全覆盖baseOperation 中定义的query 属性:
var url = require('url')
, _ = require('underscore'),
, baseOperation = {
host: 'gateway.skebby.it',
pathname: 'api/send/smseasy/advanced/http.php',
protocol: 'https',
query: {
'username': 'foo',
'password': 'bar',
}
};
var creditOperation = _.extend(baseOperation, {
query: {
'method': 'baz'
}
});
console.log(url.format(creditOperation));
我想得到这个creditOperation:
{
host: 'gateway.skebby.it',
pathname: 'api/send/smseasy/advanced/http.php',
protocol: 'https',
query: {
'username': 'foo',
'password': 'bar',
'method': 'baz'
}
}
【问题讨论】:
-
您能否在标题中添加“deep”和“assign”字样,以便通过 Google 轻松找到该主题。就像“Underscore.js 中的递归/深度扩展/赋值?”