# Classes
This video talks about the syntactic differences between creating objects with the older prototype syntax and the newer class syntax. Remember that they are both creating the same types of objects that use prototype.
Even if you create an object using the newer class syntax, you can still use the older syntax to edit the objects.
This next video explains how you can use the newer class syntax to create objects.
Here is the code sample used in the class video:
/******************************************
Intro to Classes in JS
****** JAVASCRIPT STILL USES PROTOTYPES ******
class
extends
constructor
super
get
set
static
******************************************/
class Vehicle {
constructor(_wheels) {
this.numWheels = _wheels;
}
get wheels() {
return this.numWheels;
}
set wheels(_wheels) {
this.numWheels = _wheels;
}
static accelerate() {
console.log("go faster");
}
static decelerate() {
console.log("go slower");
}
justAMethod() {
//like a function
//will be added to the prototype
}
}
let car = new Vehicle(4);
let car1 = new Vehicle(2);
let car2 = new Vehicle(6);
car.wheels = 7;
console.log(car.wheels);
Vehicle.accelerate();
class Car extends Vehicle {
constructor(_wheels, _make, _model, _year) {
super(_wheels);
this.make = _make;
this.model = _model;
this.year = _year;
}
info() {
console.log(
"The",
this.make,
this.model,
"was made in",
this.year,
"and has",
this.wheels,
"wheels"
);
}
}
let ferrari = new Car(4, "Ferrari", "Testarossa", 1985);
ferrari.info();
Car.accelerate();
Car.accelerate();
Car.accelerate();
Car.accelerate();
Car.accelerate();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69