You comparing two Arrays here, and Arrays are Objects: hence both ==
and ===
in JavaScript return true
only if both operands are in fact the same Object.
But it's not the case here, as there are two different Arrays: first, oldMousePos
, is created in mousedown
handler, and second, newMousePos
, is created in fieldMouseDown
function.
To compare them, compare each field separately:
if ( oldMousePos[0] === newMousePos[0] && oldMousePos[1] === newMousePos[1] ) {
// ..
}
... or just send each coordinate as a separate param into that function.