Your vis()
function is binding an event handler when it’s passed one, otherwise returning the status. Thus:
vis(function(event) {
if ( vis() ) {
// visible
} else {
// not visible
}
});
Or more verbosely:
var handler = function(){
// calling vis() with no arguments will return a boolean
if (vis()) {
// visible
} else {
// not visible
}
}
// if a handler is passed, it gets bound to the event
// thus, runs on *any* visibility state change
vis(handler);
solved How to use this piece of code in a function