javascript really strange behaviour
Posted
by teehoo
on Stack Overflow
See other posts from Stack Overflow
or by teehoo
Published on 2010-05-28T16:55:10Z
Indexed on
2010/05/28
17:02 UTC
Read the original article
Hit count: 163
I have the following code
if (msg.position == 0)
//removed for brevity
else if (msg.position == txtArea.value.length)
//removed for brevity
} else {
//ERROR: should not reach here.
errorDivTag.innerHTML += msg.position + " " + txtArea.value.length;
}
I'm having some really weird situations where I'm getting the error in the last code block, but the printed positions show that msg.position
is in fact equal to the txtArea.value.length
. This only happens 1% of the time, almost as if I have some kind of race-condition in my code where the two are NOT equal during the second if statement, but equal when I print in the error message.
Any ideas?
© Stack Overflow or respective owner