11
rated 0 times
[
14]
[
3]
/ answers: 1 / hits: 18668
/ 15 Years ago, fri, may 22, 2009, 12:00:00
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'
}
More From » arrays