1

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.

AlexZ
  • 11,515
  • 3
  • 28
  • 42
  • 1
    Look at [Binary logical operators ECMA](http://www.ecma-international.org/ecma-262/5.1/#sec-11.11) or [Logical operators MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Logical_operators) – Givi Jan 19 '14 at 11:35
  • This is like the 3rd time you've answered my question on SO, and for that, you're a pretty cool dude. That documentation is very clear - much appreciated. – AlexZ Jan 19 '14 at 11:38

0 Answers0