What is the difference between these various uses of the && logical operator?
From the Oliver Steele Functional.js library. Line 4, "args.length & arg]:
0 Function.prototype.partial = function(){
1 var fn = this, args = Array.prototype.slice.call(arguments);
2 return function(){
3 var arg = 0;
4 for ( var i = 0; i < args.length && arg < arguments.length; i++ )
5 if ( args[i] === undefined )
6 args[i] = arguments[arg++];
7 return fn.apply(this, args);
8 };
9 };
From bootstrap.js . Line 11 below "," hover "& & this. $ Element":
1 var Carousel = function (element, options) {
2 this.$element = $(element).on('keydown.bs.carousel', $.proxy(this.keydown, this))
3 this.$indicators = this.$element.find('.carousel-indicators')
4 this.options = options
5 this.paused =
6 this.sliding =
7 this.interval =
8 this.$active =
9 this.$items = null
10
11 this.options.pause == 'hover' && this.$element
12 .on('mouseenter.bs.carousel', $.proxy(this.pause, this))
13 .on('mouseleave.bs.carousel', $.proxy(this.cycle, this))
14 }
Also, why not just use the + arithmetic operator in the first example?
Here is another example that I have problems with grokking, from the same section of Carousel bootstrap.js:
this.options.interval
&& !this.paused
&& (this.interval = setInterval($.proxy(this.next, this), this.options.interval))
source
share