Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Tunzale1 authored Jul 7, 2023
1 parent f7fcfda commit 3a418e7
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
5 changes: 5 additions & 0 deletions hw1/Readme.md
Original file line number Diff line number Diff line change
@@ -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.
12 changes: 12 additions & 0 deletions hw1/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="./script.js"></script>
</body>
</html>
52 changes: 52 additions & 0 deletions hw1/script.js
Original file line number Diff line number Diff line change
@@ -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())

0 comments on commit 3a418e7

Please sign in to comment.