I'm trying to find an elegant way to check the if certain deep properties exist in an object. So practically trying to avoid monstrous protective checks for undefined eg.
if ((typeof error !== 'undefined') &&
(typeof error.responseJSON !== 'undefined') &&
(typeof error.responseJSON.error) &&
(typeof error.responseJSON.error.message)) {
errorMessage = error.responseJSON.error.message;
}
What I'm thinking about is a convenience-function like
if (exists(error.responseJSON.error.message)) { ... }
Any ideas? For convenience, the use of underscore-library is ok for the solution.