-1

How come the following line:

pop = setInterval(function () { doSlide($(this)) }, settings.timeoutSet); 

not sending the proper reference as the parameter.

I would like to set up the same functionality as the commented out section in the AutoSlide(theObj2) function but using the class that was sent as the selector of the function but it's not working. I keep getting [object][Object] as the console log.

How can I resolve the issue so the auto sliding function works correctly.

Si8
  • 9,141
  • 22
  • 109
  • 221
  • 2
    There are already some questions quite like your, see for example http://stackoverflow.com/questions/346015/javascript-closures-and-this – Matteo Tassinari Oct 24 '16 at 20:24

1 Answers1

1

Timeouts run in the context of window, unless told otherwise, so inside your callback this no longer points to the element, but window instead.

Instead, you can bind the callback to the element, i.e. set its context.

setInterval(function () { AutoSlide($(this)) }.bind(this), settings.timeoutSet);
Mitya
  • 33,629
  • 9
  • 60
  • 107