I understand that in Javascript classes don't really exist. An that in reality you're just making a function to construct an object for you.
Not so long ago (before syntactic sugar like "class" was introduced) the only way to mimic a class (and arguably still the best) was as follows :
function Car () {
this.type = "fancy";
this.color = "red";
}
Car.prototype.getInfo = function() {
return this.color + " " + this.type + " car";
};
let car = new Car();
I was wondering how this would look like without "new". Does the following piece of code do exactly the same as the first piece of code?
function Car(self) {
self.type = "fancy";
self.color = "red";
}
Car.prototype.getInfo = function() {
return this.color + " " + this.type + " car";
};
let car = {};
Car(car);
car.__proto__ = Car.prototype;