From 58545eb203ba14c8e99197263035345527ae2458 Mon Sep 17 00:00:00 2001 From: Md Shahadat Hossain <32963275+MdShahadatHossainbd@users.noreply.github.com> Date: Thu, 11 Mar 2021 12:47:50 +0600 Subject: [PATCH] Add files via upload --- Prototype-Inheritance.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Prototype-Inheritance.js diff --git a/Prototype-Inheritance.js b/Prototype-Inheritance.js new file mode 100644 index 0000000..afa664e --- /dev/null +++ b/Prototype-Inheritance.js @@ -0,0 +1,26 @@ +function Person(name, age){ + //parent class + this.name = name; + this.age = age; +} + +function Cricketer(name, age, type, country){ + //sub class + Person.call(this); + this.name = name; + this.age = age; + this.type = type; + this.country = country; +} + +Person.prototype = { + eat: function () { + console.log(`${this.name} is eating.`); + }, +}; + +Cricketer.prototype = Object.create(Person.prototype); +Cricketer.prototype.constructor = Cricketer; + +let shakib = new Cricketer("Shakib", 40, "All Rounder", "Bangladesh"); +console.log(shakib.eat()); \ No newline at end of file