I have a defaultObject like that:
var default = {
abc: \"123\",
def: \"456\",
ghi: {
jkl: \"789\",
mno: \"012\"
}
};
With ES2015 now being supported in all modern browsers, the native Object.assign
can be used to extend objects
Object.assign({}, _default, values)
Object.assign
Note that default
is a reserved keyword, and can't be used as a variable name
The original answer, written in 2013 :
Since this is tagged with jQuery, you could use $.extend for a simple cross-browser solution
var temp = {};
$.extend(true, temp, _default, values);
values = temp;