Friday, March 28, 2008

Unidentifiable error

Came across an interesting error while starting with script.aculo.us A test code was working fine. I moved the same script to the real project code. Then the script started throwing error, 'undefined object'. Spent lot of time in comparing the test code and actual one. Couldn't find any issue.

Then placed few alert statements and narrowed down the issue by applying divide n conquer. What caught was this function :
function $(id){return document.getElementById(id)}

Seems like scriptaculous.js is using prototype.js and the later is defining a function with the same signature as above. After going thru the function defined in prototype.js, I found that to be sophisticated and served my requirement too. I commented my definition and the page flies through without error.

Moral : don't duplicate function names, it is going to be lot difficult to debug.

No comments: