Could do with some smoothing and polishing. Jerks all over the place. Also, what is with this new fashion of declaring functions as anonymous methods? var recalculateLimits = function () { /* snip */ }; var update = function () { recalculateLimits(); onScroll(); }; Have I missed a memo? EDIT: I forgot to say apart from my moaning, does the job, good code, good job! And it's only jerky when you use the scroll button o…
I learned this method with the book JavaScript the Good Parts, though it was a while ago and I can't remember the specific reasoning behind the books' recommendation. From the other commenter's SO link, I found this link to go more in depth into the differences of declaring functions, and it seems to come down to having stricter control on the order of events with no surprises. http://javascriptweblog.wordpress.com/2…
But about the hoisting problems... For me, the real problem is that you're declaring a function inside a function. Or using variables with the same name. That's a bad practice, it doesn't make sense. It should be avoided instead of using language constructs to work around it.