I'm passing parameters to a function in a JavaScript library I wrote:
ffff.setup({
'size':{'width':'100','height':'100'}
});
In the function, I pick them up:
var ffff = {
setup: function(config) {
if (config["size"]["width"]) {my_width = config["size"]["width"];}
if (config["size"]["height"]) {my_height = config["size"]["height"];}
}
}
My error is, if I do not specify a parameter, I get a Cannot read property 'height' of undefined
error: (the error occurs on if (config["size"]["height"])
)
ffffr.setup({
'size':{'width':'100'}
});
How should I detect if a variable has been provided or not?