My code is getting really quite polluted with:
if( typeof( objectVar ) === 'object' && objectVar !== 'null' )
if( typeof( objectVar.other ) === 'object' && objectVar.other !== 'null' )
// OK, objectVar.other is an object, yay!
}
}
This is a little ridiculous. I am after a function that reads like this:
isProperObject( objectVar.other );
Considering that if objectVar
is not defined, this will actually fail miserably, maybe I should do instead:
isProperObject( 'objectVar.other' );
Then the function could eval()
it. But no! It cannot do that, because isProperObject()
would be in a different scope, one without objectVar
.
So, it could be:
isProperObject( objectVar, 'other' )
OK this could work. Is there a function like this that is actually commonly used?