development of the game progressed along the different levels and code scenarios it became
extremely difficult for me to keep tabs on all the errors that crept in. Eventually, after a little
research I realised that there was an amazingly simple way to keep tabs on the code and to
see what was happening. Let me share my findings with you.
Finding an error line number by using Firefox Firebug
Basically I found it handy to add this line to each JS object:
console.log((new Error).lineNumber + 'description of object')
This way as your code grows or as you change/replace something in your code you can
follow its logic and quickly find any place as you can clearly see a line number.
This is how it looks in Firebug:
As you see, I can follow my script logic while it runs and see the line numbers. This way
when I change or add new stuff to it I will get new line numbers dynamically. Of course, if
your script is just up to a hundred lines it doesn’t matter.
OK, so this is great and it works in Firefox but what about other browsers? What about errors
in IE browser?
Find an error line number by using window.onerror method
Why didn’t anyone tell me about this simple method? It would have saved me hours of work.
The IE browser doesn’t always show line numbers nor explain what kind of error you have.
This [window.onerror] method can give at least the line number where IE was stuck. Just add
this on top of your JS code: