1

hey guys i was just going through the code of carasoul.js and came across the following function .

  Carousel.prototype.cycle = function (e) {

    e || (this.paused = false)

    this.interval && clearInterval(this.interval)

    this.options.interval
      && !this.paused
      && (this.interval = setInterval($.proxy(this.next, this), this.options.interval))

    return this
  }

can somebody tell me why the check on e in the 1st line of the function ? i have seen this in almost most of the bootstrap plugins . can somebody explain the significance of this check ? and where us e being passed from ??

The two things i found out is cycle get's called from the function Plugin , on line 186 and e if console logged gives the following output :

Object { originalEvent: mouseover, type: "mouseover", isDefaultPrevented: bb(), timeStamp: 0, jQuery1112044026608114512766: true, toElement: undefined, screenY: 407, screenX: 643, pageY: 310, pageX: 643, 23 more… } 

the Entire plugin can be here.

EDIT :: I was specifically asking "WHY" , not "What is e" , also my question is more contextual and relates to a code convention of a popular framework,(bootstrap3.2+) , i am not asking a beginner question as to how ?

Thank you .

Alex-z

Alexander Solonik
  • 9,466
  • 17
  • 65
  • 157

1 Answers1

1

The function cycle is being called in three different forms:

  • cycle()
  • cycle(true)
  • as a event handler for mouseleave. e is therefor the event parameter.

With the check the first call can be distinguished from the other two calls. So the information if Carousel is in the pause-mode can be transmitted like this even if you can not set the parameters yourself (event).

ImreNagy
  • 511
  • 2
  • 10