From 3a418e71a46bad80cfd54d997d3fe4425cd1f6f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=BCnzal=C9=99?= <114104944+Tunzale1@users.noreply.github.com> Date: Fri, 7 Jul 2023 19:09:20 +0400 Subject: [PATCH] Add files via upload --- hw1/Readme.md | 5 +++++ hw1/index.html | 12 ++++++++++++ hw1/script.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 hw1/Readme.md create mode 100644 hw1/index.html create mode 100644 hw1/script.js diff --git a/hw1/Readme.md b/hw1/Readme.md new file mode 100644 index 0000000..ac446f4 --- /dev/null +++ b/hw1/Readme.md @@ -0,0 +1,5 @@ +- *Explain in your own words how you understand prototypical inheritance works in JavaScript.* +- Mainly, prototypical inheritance is technique that used for objecs, so ,objects can inherit properties and methods from other objects. Object's prototype when each object has an internal "link" to another object. When we want to access a property on an object, js first checks if that property exists on the object itself. If it doesn't, it follows the prototype chain. This process continuing until it finds the property or until it reaches the end of the prototype chain. If prototype can be found then js returns its value. + +- *Why is it necessary to call super() in the constructor of a child class?* +- If you check my homework, in Programmer class i used super(). Because Programmer class (child) extends from Employee class (parent). And properties of Employee are same with properties of Programmer. So for not repeating same code we use super() and it establish inheritance relationship, Initialize the parent class. diff --git a/hw1/index.html b/hw1/index.html new file mode 100644 index 0000000..7b3c7e8 --- /dev/null +++ b/hw1/index.html @@ -0,0 +1,12 @@ + + + + + + + Document + + + + + \ No newline at end of file diff --git a/hw1/script.js b/hw1/script.js new file mode 100644 index 0000000..9426b0d --- /dev/null +++ b/hw1/script.js @@ -0,0 +1,52 @@ +class Employee{ + constructor(name,age,salary) { + this.name = name; + this.age = age; + this.salary = salary; + } + getName(){ + return this.name + } + getAge(){ + return this.age + } + getSalary(){ + return this.salary + } + setName(name) { + this.name = name; + } + + setAge(age) { + this.age = age; + } + + setSalary(salary) { + this.salary = salary; + } + +} +let a = new Employee ("Tunzala","20","1000") +console.log(`${a.getName()} has ${a.getAge()} and gets ${a.getSalary()} from company`) + +class Programmer extends Employee{ + constructor(name,age,salary,lang){ + super(name, age, salary) + this.lang=lang; + } + getLanguage(){ + return this.lang + } + setLanguage(lang) { + this.lang = lang; + } + getMultipliedSalary(){ + return super.getSalary()*3 + } +} + +let b = new Programmer ("Tunzala",20,1000,"JavaScript") +console.log(`${b.getName()} learns ${b.getLanguage()} and earns ${b.getMultipliedSalary()} `) +let i = new Programmer ("Alex", 34, 2000, "C++, Python" ) +console.log(i) +console.log(i.getMultipliedSalary()) \ No newline at end of file