有没有办法获得 Underscore.jsextend功能:
将源对象中的所有属性复制到目标对象,然后返回目标对象。它是有序的,因此最后一个源将覆盖先前参数中的同名属性。
...递归工作?
实际上,query属性 increditOperation将完全覆盖query定义的属性baseOperation:
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'
}
}