If I have a javascript object/assoc. array defined like this:
function somefunction(options) {
var defaults = {
prop1: 'foo',
prop2: 'bar'
};
//Do stuff here
}
and I want to use this as the default values for the function. So when the function gets called I want to populate the options
variable with the values in defaults
, but only if they don't exist in options
.
So lets say that this was called
somefunction({ prop1: 'fish' });
How can I make it so that options
gets merged with defaults
such that I get this
{
prop1: 'fish',
prop2: 'bar'
}