Grokking Advanced JavaScript
0% completed
Classes
The Car constructor function and its displayInfo method from the previous lesson were written in two separate places: the function, and an assignment to Car.prototype. The class keyword puts both in one block.
A 2021 Toyota Corolla function true false TypeError: Class constructor Car cannot be invoked without 'new'
The output shows that a class is not a new kind of object model. typeof Car is "function", the prototype of myCar is still Car.prototype, and displayInfo is stored on that prototype, not on myCar. The `new
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%