We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 46ba2b7 commit a889765Copy full SHA for a889765
1 file changed
OOP/method-overriding.js
@@ -0,0 +1,22 @@
1
+function Person(name, age) {
2
+ this.name = name;
3
+ this.age = age;
4
+}
5
+Person.prototype.greet = function () {
6
+ return `${this.name} is ${this.age} years old`;
7
+};
8
+
9
+function Racer(name, age, car) {
10
+ Person.call(this, name, age);
11
+ this.car = car;
12
13
14
+Racer.prototype = Object.create(Person.prototype);
15
+Racer.prototype.greet = function () {
16
+ return `${Person.prototype.greet.call(this)} . He is a celebrity`;
17
+ //method overriding
18
19
20
+const racerOne = new Racer("Pain", 25, "BMW");
21
+console.log(racerOne.age);
22
+console.log(racerOne.greet());
0 commit comments