Adds the function to an object that returns a parameter value or a default value (in case of parameter is missing in object)
Use cases:
- Options backward compatability
- Local and global parameters (global as defaults)
- Getting missing localization strings
Example:
var obj = {
param1: "a",
param2: 10,
param3: {
param4: {
param5: 25
}
}
};
var defaultObj = {
param1: "a1",
param2: 11,
param3: {
param4: {
param5: 25,
param6: 25
}
},
param7: "b"
};
initDefaultParams(obj, defaultObj);
var param1 = obj.getParamOrDefault('param1'); //param1 = "a"
var param7 = obj.getParamOrDefault('param7'); //param7 = "b"
var param345 = obj.getParamOrDefault('param3.param4.param5'); //param345 = 25
var param346 = obj.getParamOrDefault('param3.param4.param6'); //param346 = 25