<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Гонки23</title>
</head>
<body>
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
<script>
'use strict';
let Car = function (x, y) {
this.x = x;
this.y = y;
this.spead = 40;
this.draw();
};
Car.prototype.draw = function () {
let carHtml = '<img src="http://nostarch.com/images/car.png">';
this.carElement = $(carHtml);
this.carElement.css({
position: 'absolute',
left: this.x,
top: this.y
});
$('body').append(this.carElement);
};
Car.prototype.moveRight = function (distance) {
this.x +=distance;
this.carElement.css({
left: this.x,
top: this.y
});
};
Car.prototype.moveLeft = function (distance) {
this.x -=distance;
this.carElement.css({
left: this.x,
top: this.y
});
};
Car.prototype.moveUp = function (distance) {
this.y -=distance;
this.carElement.css({
left: this.x,
top: this.y
});
};
Car.prototype.moveDown = function (distance) {
this.y +=distance;
this.carElement.css({
left: this.x,
top: this.y
});
};
let tesla = new Car(20, 20);
let nissan = new Car(300, 70);
tesla.moveDown(200);
let k = tesla.moveDown.bind(tesla);
setInterval(k, 480);
</script>
</body>
</html>