We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 622e13f commit 735eb36Copy full SHA for 735eb36
OOP/function-constructors.js
@@ -0,0 +1,16 @@
1
+//! Functions that are called with the new keyword are usually called constructor functions
2
+function Car(brand, year) {
3
+ this.brand = brand;
4
+ this.year = year;
5
+ this.status = function () {
6
+ return `${this.brand} ${this.year}`;
7
+ };
8
+ //? do not `return` something on constructor function
9
+}
10
+
11
+let newCar = new Car("Toyota", 2020); // newCar is an instance of Car
12
+let newCar2 = new Car("Honda", 2300);
13
+let newCar3 = new Car("BMW", 2100);
14
+console.log(newCar.status());
15
+console.log(newCar2.status());
16
+console.log(newCar3.status());
0 commit comments