It’s hard to figure out how to describe this in a one sentence title.
Let’s consider this code:
for (var peonIndex = 0; peonIndex < peons.length; peonIndex++) {
var peon = peons[peonIndex];
var item = peon.getNearest(items);
var distance = peon.distance({x:1,y:1});
}
When peons.length == 0, the getNearest() does not throw an error, but for distance() I get an undefined is not a function.
Even if I wrap the above code in
if ( peons.length > 0 ) { }
I still get the same error. Is there some error detection happening to the code before it starts running? Any ideas on a way around this?