You can use the operator or to assign default values ββif they are not defined, for example:
var slider = { init:function(data){ var fish = data.fish || "default value"; } }
Or you can make the extend function to combine two objects similar to the jQuery extend function:
function extend (obj1, obj2) { var result = obj1, val; for (val in obj2) { if (obj2.hasOwnProperty(val)) { result[val] = obj2[val]; } } return result; } var defaults = {val1: 1, val3: 3, fish: 'fish'}; extend(defaults, {val2: 2});
source share