views:

1026

answers:

3

I have a plugin that access the length property on many elements. However, the javascript console points to line 12 of jquery.min.js.

How can I backtrace to find which line of my plugin has null variable attempting to access length?

+1  A: 

How can I backtrace to find which line of my plugin has null variable attempting to access length?

firebug is great way to debug those errors.

alt text

Sarfraz
I have firebug but where am I supposed to put the `debugger` keyword in my script? guess/check?
macek
@macek: see Debug JavaScript with Firebug: http://thecodecentral.com/2007/08/01/debug-javascript-with-firebug
Sarfraz
+1  A: 

Not the solution for this time, but do yourself a huge favor, don't develop plugins on minified jQuery. Also, you should always check if the element exists at all before checking the length.

Aaron Harun
Aaron, this is *somewhat* beside the point. Either way, I need to see where the error originated, as I'm assuming the minified jQuery is not the issue.
macek
+1  A: 

If you use minified scripts any debugger (like totally the best firebug) will show you the same problematic line and this information is useless (minified scripts are hard to read and understand and they are written in 1 line).

Few ways to solve problems like this:

  1. As told before me: for developing use not minified scripts, debugger will show you the line that means something and you if you are lucky you can find very useful comments of developers.
  2. If you can't find full version of the script use unminifier like this one: http://jsbeautifier.org/ (paste minified script and click button below). Add to your project uminified script and run invalid function again. Debugger again will show you the line, but this time you will see a real logic line and you can understand what is the problem in most cases.
  3. Debugger will show you which script throws problem. Check if there any any new versions of this script. I had the same problem once, found line of the minified script, name of plugin (few lines above in copyrights) and then found that there is a new version available. Reviewed changelog and there was: "Added multiple 'sanity checks' throughout the code for potential unknown attribute values" - headshot :) Updated script and everything was fine from now without special debugging taking hours.
  4. Google your error with script name - it helped me so many times.. Probably you did it, but maybe you didn't try with speech marks "" - google will return pages with exact phrase in text.

Hope some of this will help you out. Good luck.

s3m3n