We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 735eb36 commit 8e29d85Copy full SHA for 8e29d85
1 file changed
OOP/prototype.js
@@ -0,0 +1,18 @@
1
+//! Prototypes are the mechanism by which JavaScript objects inherit features from one another.
2
+function Car(brand, year) {
3
+ this.brand = brand;
4
+ this.year = year;
5
+}
6
+Car.prototype.info = function () {
7
+ return `${this.brand} ${this.year}`;
8
+};
9
+Car.prototype.speed = function (speed = "fast") {
10
+ return `${this.info()} is ${speed}`;
11
12
+let newCar = new Car("Toyota", 2020);
13
+let newCar2 = new Car("Honda", 2300);
14
+let newCar3 = new Car("BMW", 2100);
15
+
16
+console.log(newCar2.info());
17
+console.log(newCar.speed());
18
+console.log(newCar3.speed("faster"));
0 commit comments