Я определил свой класс так:
function Slot(slot, maxSpeed, timer) {
this.slot = slot;
this.speed = 0;
this.maxSpeed = maxSpeed;
this.timer = timer;
this.interval = null;
this.go = function() {
var $slot = $(this.slot);
console.log(this.slot);
$slot.addClass('motion');
$slot.spStart();
this.interval = window.setInterval(function() {
var step = Math.floor(Math.random() * ((this.speed / 100) * 25)) + 1;
if (this.speed < (this.maxSpeed / 2)) {
this.speed += step;
}
if (this.speed >= (this.maxSpeed / 2)) {
this.speed -= step;
}
console.log(this.slot);
$slot.spSpeed(this.speed);
}, timer);
};
$(this.slot).pan({ fps: '30', dir: 'down' });
$(this.slot).spStop();
}
Первый console.log возвращает ожидаемое значение, но как только я попаду в функцию setInterval, все переменные (this.slot, this.speed) станут неопределенными? Хотя я все еще в их поле зрения...