On the MDN page for the wheel
event, there is a code sample which includes the following at lines 30-31:
function( originalEvent ) {
!originalEvent && ( originalEvent = window.event );
The second line seems to take a number of shortcuts that rely on the way JavaScript evaluates boolean expressions internally. If I understand correctly, its purpose is to set originalEvent
to window.event
if no argument is passed. Its action is the same as the following:
if (!originalEvent) {
originalEvent = window.event;
}
or
orginalEvent = (originalEvent) ? orginalEvent : window.event;
What advantages are there in using the construction from the MDN site?
To add more obscurity you could also use
There are no correct way of doing this, and they are all perfectly valid, I quite often use the one above, since i think it it more easily readable (though many will shake their fist at me for doing it). I also believe that you could get all method to go through most JSLint'ers with their default setting, so it really is a matter of style.