I have the following function in JavaScript, and when I run it through JSLint, she yelled at me as I call it.
function getPos(event, element) { var x = event.clientX, y = event.clientY, currentElement = element; do { x -= currentElement.offsetLeft - currentElement.scrollLeft; y -= currentElement.offsetTop - currentElement.scrollTop; } while ((currentElement = currentElement.offsetParent)); return { x: x, y: y }; }
In particular, an inline assignment expression in a while loop. I decided that double parentheses were the standard way of saying: "I expect the return value from the assignment expression to be assigned to the type for the conditional expression." JSLint does not seem to agree, even when I include assignment expressions. Then I tried to add !! ahead, and JSLint complains that it is "confusing use." So my question is, what is the proper way to format this?
EDIT: In "this" I was referring specifically to the expression inline assign. The purpose of my question was to clarify what an acceptable standard for this particular line was if someone really wanted to use this, and although I agree that the best answer to this question is the most correct way to write a function, this not the answer to the question I asked.
javascript jslint standards
Patrick roberts
source share