Does anyone have an explanation of how javascript could do this. Somehow this function is both true and false at the exact same time. This is just one pass, no looping or anything.
console.log(key); if (this.watches.get(key)) { console.log('found it'); } else { console.log('whhhat?'); } console.log(this.watches);
Firebug Console logs as is.
search-key found it Object search-key=Object $family=Object whhhat? Object search-key=Object $family=Object
[EDIT] Here it is. The full script and the block of output above is copy and paste from firebug. This is the strangest thing I have ever seen. http://snipt.org/Hkl
I use mootools framework so the this.watches = $H({}); is a hashtable. I was using an Array and was experiencing the exact same issue, then switched it to $H({}) because I thought i was doing something wrong.
If this
is produced by:
Then this is obviously not just one pass.
This is not to say that it’s in a loop or anything, just that this code is being called more than once.
One might say
The answer is: we don’t really know because we don’t see all the code.
The most likely scenario is that
keyin the second time is the empty stringtry
console.log('')it prints nothingalso try this:
copy the output and paste it in any text editor (i.e. paste it as plain text)
it looks like there was nothing between 1 and 2, even though the console does show a cue of an empty line, but this cue disappears when you copy-paste the output as plain text.
UPDATE
well, if this process is initiated by the call to
WCHistory.implement(..), and this method is being called twice, then obviously, the second time, for some reason, the key is empty.Try this
Change
console.log(key)toconsole.log('key: ' + key)and you should see something like this: