Почему js ругается на this.carElem.css? я же при вызове метода draw ее определяю
Cannot read property 'css' of undefined
let Car = function(x, y){
this.x = x;
this.y = y;
};
Car.prototype.draw = function(){
this.carHTML = '<img src="1.png" height="60">';
this.carElem = $(this.carHTML);
this.carElem.css({
position: 'absolute',
left: this.x,
top: this.y
});
$('body').append(this.carElem);
};
Car.prototype.moveRight = function(){
this.x += 5;
this.carElem.css({
left: this.x,
top: this.y
});
};
let bmw = new Car(1,2);
let mercedes = new Car(200,300);
bmw.draw();
mercedes.draw();
let speedBmw = setInterval(bmw.moveRight, 1000);