在Underscore.js中递归/深度扩展/分配?
- 论坛
- 在Underscore.js中递归/深度扩展/分配?
8 浏览
在Underscore.js中递归/深度扩展/分配?
有没有办法让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' } }