Skip to content

Commit 735eb36

Browse files
committed
function-constructors
1 parent 622e13f commit 735eb36

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

OOP/function-constructors.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)