Lets say I'm expecting a variable in a function and if my_var[2].attr[4][2] exists then I can continue with my execution, otherwise something went wrong along the way.
The only way I know how to do this is with the following:
function isdef(x) { return typeof x !== 'undefined'; }
function expects_variable(x) {
if (isdef(x) && isdef(x.length) && x.length >= 2 && isdef(x[2].attr) && isdef(x[2].attr.length) && x[2].attr.length >= 4 && isdef(x[2].attr[4].length) && x[2].attr[4].length >= 2) {
//phew, finally!
}
}
ok maybe a bit absurd example but I have to deal with shorter versions of these all the time.
Essentially, I want to check for the existence of x[2].attr[4][2] without verifying that the whole structure up until that point is valid as well. Is there a way?