I have a Javascript function written as follows:
function refresh(selection, xPath, yPath, xAnnotationSelection, yAnnotationSelection) {
var coords = selection.node().__coord__;
...
}
The function is being called sometimes, with the variable selection
not having been set yet, which causes the following exception to be thrown:
Uncaught TypeError: Cannot read property 'coord' of null
What is a better way to write the statement so that it first checks to make sure that selection
is not null, before attempting to call a method on it?
Pseudocode:
var coords = (selection ? ((selection.node ? selection.node().__coord__: null) : null);