Yesterday it have read this blog-article by John Resig: http://ejohn.org/blog/comparing-document-position/
This snippet I don't understand:
function contains(a, b){
return a.contains ?
a != b && a.contains(b) :
!!(a.compareDocumentPosition(b) & 16);
}
The first expression is clear: If a isn't identical with b and b is contained in a then return true. But what is the purpose of the two-times negation in the second expression? The return of compareDocumentPosition() is bitwise compared with 16. => Results either in 16 or 0. Let's say it is 16 then it becomes false after the first negation. Then true again after the second negation. In case of 0 it becomes true and then false again.
Does anyone understand the code and can explain it?