Here is some source code from jquery, namely from the function jQuery.speed that deals with animations:
jQuery.speed = function( speed, easing, fn ) {
var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : {
complete: fn || !fn && easing || jQuery.isFunction( speed ) && speed,
duration: speed,
easing: fn && easing || easing && !jQuery.isFunction( easing ) && easing
};
/*SOME OTHER CODE*/
};
What's going on with the "opt" definition? I get that the first line says "opt equals either: speed extended if speed is an object, or otherwise a new object defined as follows". But what about, for example, the property definition for "complete" in the object literal? I get that there are three conditions, but it doesn't seem to say what is supposed to happen if any of those conditions is met. As far as I can tell, it says "if fn exists, complete = fn; otherwise, if there is no fn but easing exists, complete = easing (but why?); otherwise, if speed is a function, complete equals speed (again, where does it specify speed)?" Those three property definitions are very confusing to me.