Line 4140 of jQuery 1.7rc1:
while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {}
This is weird to my eyes. Is it equivalent to
while( elem && elem.nodeType !== 1 ) elem = elem.previousSibling;?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, it is not equivalent to what you have. The original code:
is equivalent to this:
Logically, it says to loop while there is a
previousSiblingand while thepreviousSibling'snodeType !== 1and assignelemto thatpreviousSibling.The assignment in the original while condition is a shortcut that saves a separate assignment and saves an extra reference level in the
nodeTypecheck.Breaking down the while loop even more, it’s the same as this:
This part:
assigns
elem.previousSiblingtoelemand then evaluates whether elem is truthy or not.