var defaults = {
CrfFlag: null,
Table: null,
Config: { DS: null, UserID: null, Password: null }
}
var opts = {
CrfFlag: "temp",
Table: "t1",
foo: "Foo"
}
我想要如下结果:我不想在我的结果对象中使用 foo
var result = {
CrfFlag: "temp",
Table: "t1",
Config: { DS: null, UserID: null, Password: null }
}
我刚刚尝试了下面的代码($.extend),但它不满足我的要求
var result = $.extend({}, defaults, opts);
<br/>
result = {
CrfFlag: "temp",
Table: "t1",
foo: "Foo",
CABIDBConfig: { DS: null, UserID: null, Password: null }
}
提前致谢
最佳答案
var 默认值 = { CrfFlag:空, 表:空, 配置:{ DS: null, UserID: null, Password: null }
变种选择= { CrfFlag:“温度”, 表:“t1”, 富:“富” } 变种结果= { CrfFlag:“温度”, 表:“t1”, 配置:{ DS: null, UserID: null, Password: null } } 这是覆盖行为的正确覆盖方式
关于javascript - 仅将一个对象的值复制到另一个对象而不是属性 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23509695/