├── 2-dars-OOP
├── javascript
│ └── script.js
└── index.html
├── .idea
├── vcs.xml
├── git_toolbox_blame.xml
├── .gitignore
├── modules.xml
├── material_theme_project_new.xml
└── JS_Lesson.iml
├── 6-dars OOP
├── javascript
│ └── script.js
└── index.html
├── 1-dars-OOP
├── index.html
└── javascript
│ └── script.js
├── 3-dars OOP
├── index.html
└── javascript
│ └── script.js
├── 4-dars OOP
├── index.html
└── javascript
│ └── script.js
└── 5-dars OOP
├── index.html
└── javascript
└── script.js
/2-dars-OOP/javascript/script.js:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/git_toolbox_blame.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/material_theme_project_new.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/JS_Lesson.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/6-dars OOP/javascript/script.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | class Account {
4 | #balance//private fields
5 | constructor(owner, currency, pin) {
6 | this.owner = owner
7 | this.currency = currency
8 | this.pin = pin
9 | this.#balance = 1000
10 | }
11 |
12 | deposit(amount) {
13 | this.#balance += amount
14 | console.log(`${amount} ${this.currency} qo‘shildi.`)
15 | }
16 |
17 | withdraw(amount) {
18 | if (amount > this.#balance) {
19 | console.log('You have not enough money')
20 | } else {
21 | this.#balance -= amount
22 | console.log(`${amount} ${this.currency} chiqildi.`)
23 | }
24 | }
25 |
26 | getBalance() {
27 | console.log(this.#balance)
28 | }
29 | }
30 |
31 | const acc1 = new Account('Sardorbek', 'USD', 1111)
32 | acc1.deposit(3000)
33 | acc1.getBalance()
--------------------------------------------------------------------------------
/1-dars-OOP/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Developer Skills & Editor Setup
9 |
32 |
33 |
34 |
35 | Object Oriented Programming in JavaScript
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/2-dars-OOP/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Developer Skills & Editor Setup
9 |
32 |
33 |
34 |
35 | Object Oriented Programming in JavaScript(Classes)
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/3-dars OOP/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Developer Skills & Editor Setup
9 |
32 |
33 |
34 |
35 | Object Oriented Programming in JavaScript(Classes)
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/4-dars OOP/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Developer Skills & Editor Setup
9 |
32 |
33 |
34 |
35 | Object Oriented Programming in JavaScript(Classes)
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/6-dars OOP/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Developer Skills & Editor Setup
9 |
32 |
33 |
34 |
35 | Object Oriented Programming in JavaScript(Classes)
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/5-dars OOP/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Developer Skills & Editor Setup
9 |
32 |
33 |
34 |
35 | Object Oriented Programming in JavaScript(Classes)
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/4-dars OOP/javascript/script.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | /* inheritamce class */
3 | /* bu class ota class */
4 | /* class Payment {
5 | constructor(amount) {
6 | this.amount = amount
7 | }
8 | proccess() {
9 | console.log(`${this.amount} pul orqali to'landi`)
10 | }
11 | }
12 |
13 | class CashPayment extends Payment {
14 | constructor(amount, price) {
15 | super(amount)
16 | this.price = price
17 | }
18 | proccess() {
19 | console.log(`${this.amount} pul orqali ${this.price} so'm to'landi`)
20 | }
21 | }
22 |
23 | class CardPayment extends CashPayment {
24 | constructor(amount, price, cardNumber) {
25 | super(amount, price)
26 | this.cardNumber = cardNumber
27 | }
28 | proccess() {
29 | console.log(`${this.amount}${this.amount.toLowerCase()==='naqd'?" pul":""} orqali ${this.price} so'm karta raqamiga yo'naltirildi ${this.cardNumber}`)
30 | }
31 | }
32 |
33 | const pay = new CardPayment("Click", 145000,'8600 4523 5468 9800')
34 | pay.proccess()
35 | */
36 |
37 | class ExtensibleFunction extends Function {
38 | constructor(f) {
39 | return Object.setPrototypeOf(f, new.target.prototype)
40 | }
41 | }
42 | class MeningFunksiyam extends ExtensibleFunction {
43 | constructor(ism) {
44 | // super orqali funksiya yaratamiz
45 | super(function () {
46 | return `Salom, ${ism}!`
47 | })
48 | this.ism = ism
49 | }
50 |
51 | // Qo'shimcha metod
52 | tanishuv() {
53 | console.log(`Men ${this.ism} bilan tanishmoqchiman`)
54 | }
55 | }
56 | const something=new MeningFunksiyam("Sarvarbek")
57 | something.tanishuv()
58 |
59 |
60 | // class Smth extends ExtensibleFunction {
61 | // constructor(x) {
62 | // super(function () { return x }) // closure
63 | // // console.log(this); // function() { return x; }
64 | // // console.log(this.prototype); // {constructor: …}
65 | // }
66 | // }
67 | // class Anth extends ExtensibleFunction {
68 | // constructor(x) {
69 | // super(() => { return this.x }) // arrow function, no prototype object created
70 | // this.x = x
71 | // }
72 | // }
73 | // class Evth extends ExtensibleFunction {
74 | // constructor(x) {
75 | // super(function f() { return f.x }) // named function
76 | // this.x = x
77 | // }
78 | // }
79 |
--------------------------------------------------------------------------------
/1-dars-OOP/javascript/script.js:
--------------------------------------------------------------------------------
1 | /* const user1 = {
2 | name: "Ali",
3 | age: 25,
4 | greet: function () {
5 | console.log(`Salom, mening ismim ${this.name}!`)
6 | }
7 | }
8 | const user2 = {
9 | name: "Bekzod"
10 | age: 20,
11 | greet: function () {
12 | console.log(`Salom, mening ismim ${this.name}!`)
13 | }
14 | }
15 | const user3 = {
16 | name: "Sardorbek",
17 | age: 20,
18 | greet: function () {
19 | console.log(`Salom, mening ismim ${this.name}!`)
20 | }
21 | }
22 |
23 | user1.greet()
24 | user2.greet()
25 | user3.greet()
26 | */
27 |
28 | //constructor function
29 | /* const User = function (name, age) {
30 | this.name = name
31 | this.age = age
32 | this.toast = function () {
33 | alert(`Hello, my name is ${this.name}, and I'm ${this.age} years old.`)
34 | }
35 | this.calcAge = function () {
36 | console.log(`I was born in ${2025 - this.age} years`)
37 | }
38 | }
39 |
40 | const sardor = new User("Sardorbek", 20)
41 | const bekzod = new User("Bekzod", 20)
42 | const ali = new User("Ali", 25) */
43 |
44 | /* function Car(brend="NO brend",model="NO model",year="NO year",color="NO color"){
45 | this.brend=brend
46 | this.model=model
47 | this.year=year
48 | this.color=color
49 | this.info=function(){
50 | console.log(`Brend:${this.brend}\nModel: ${this.model}\nYear: ${this.year}\nColor: ${this.color}`)
51 | }
52 | }
53 |
54 | const bmw=new Car()
55 | const merc=new Car("Mercedes","C300",2020,"white")
56 | bmw.info()
57 | console.log(bmw);
58 |
59 | merc.info()
60 | */
61 |
62 | /* function Person(name, age) {
63 | this.name = name
64 | this.age = age
65 | }
66 | Person.prototype.calcAge=function(){
67 | console.log(`I was born in ${2025 - this.age} years`)
68 | }
69 | const person1 = new Person("Ali", 25)
70 | console.log(Person.prototype,person1);
71 |
72 | person1.calcAge() */
73 |
74 | /* function Person(name, age) {
75 | this.name = name
76 | this.age = age
77 | }
78 | function Child(name, age) {
79 | this.name = name
80 | this.age = age
81 | }
82 | Person.prototype.greet = function () {
83 | console.log(`Salom, mening ismim ${this.name}!`)
84 | }
85 |
86 | const person1 = new Person("Ali", 25)
87 | const person2 = new Child("Vali", 30)
88 | console.log(person1.__proto__===Person.prototype)
89 | console.log(person2.__proto__===Child.prototype) */
90 |
91 | /* const Car = function (make, speed) {
92 | this.make = make
93 | this.speed = speed
94 |
95 | this.accelerate = function () {
96 | this.speed += 10
97 | console.log(`${this.make} mashina endi ${this.speed}km/h harakatlanmoqda!`)
98 | }
99 |
100 | this.break = function () {
101 | this.speed -= 5
102 | console.log(`${this.make} mashina endi ${this.speed}km/h harakatlanmoqda!`)
103 | }
104 | }
105 |
106 | const nexia2=new Car("Nexia 2",50)
107 | const nexia3=new Car("Nexia 3",60)
108 | nexia2.accelerate()
109 | nexia2.break() */
--------------------------------------------------------------------------------
/3-dars OOP/javascript/script.js:
--------------------------------------------------------------------------------
1 | //Object create() inheritance
2 |
3 | /* const Teacher = function (name, age) {
4 | this.name = name
5 | this.age = age
6 | }
7 | Teacher.prototype.calcAGe = function () {
8 | return console.log(`${this.name}ning tug'ilgan yili:${2025 - this.age}`)
9 | }
10 | Teacher.prototype.sayHello = function () {
11 | return console.log(`Assalamu alaykum hurmatli ${this.name}`)
12 | }
13 | const newTech = new Teacher('Sarvinoz', 20)
14 |
15 | const Student = function (name, age, course) {
16 | Teacher.call(this, name, age)
17 | this.course = course
18 | }
19 |
20 | const Other = function (name, age, course, work) {
21 | Student.call(this, name, age, course)
22 | this.work = work
23 | }
24 | Student.prototype = Object.create(Teacher.prototype)
25 | Student.prototype.constructor = Student
26 |
27 | Other.prototype = Object.create(Student.prototype)
28 | Other.prototype.constructor = Other
29 |
30 |
31 | const student1 = new Student("Sardorbek", 21, "Front")
32 | const student2 = new Student("Sarvarbek", 30, "Front")
33 | const other1 = new Other("Kimdur", 35, "Back", "Not working")
34 | console.log(other1)
35 | console.log(student1)
36 |
37 |
38 | student1.calcAGe()
39 | student2.calcAGe()
40 | student1.sayHello()
41 | other1.calcAGe() */
42 |
43 |
44 | /* const Car = function (make, speed) {
45 | this.make = make
46 | this.speed = speed
47 | }
48 | Car.prototype.break = function () {
49 | this.speed -= 10
50 | console.log(`${this.make} endi ${this.speed} km/h da harakatlanmoqda!`)
51 | }
52 |
53 | const EV = function (make, speed, charge) {
54 | Car.call(this, make, speed)
55 | this.charge = charge
56 | }
57 | EV.prototype = Object.create(Car.prototype)
58 | EV.prototype.chargeBattery = function (chargeTo) {
59 | this.charge = chargeTo
60 | console.log(`${this.make} quvvatlandi:${this.charge}%`)
61 | }
62 |
63 | EV.prototype.accelarate = function () {
64 | if (this.charge > 0) {
65 | this.charge--
66 | this.speed += 20
67 | console.log(`${this.make} endi ${this.speed} km/h da harakatlanmoqda. Quvvati:${this.charge}%`)
68 | } else {
69 | console.log(`Mashinani quvvatlang`)
70 | }
71 | }
72 | const byd = new EV("Build Your Dreams", 180, 3)
73 | byd.accelarate()
74 | byd.accelarate()
75 | byd.accelarate()
76 | byd.chargeBattery(15)
77 | byd.accelarate() */
78 |
79 |
80 | /* Inheritance Classes */
81 | class Payment {
82 | constructor(amount) {
83 | this.amount = amount
84 | }
85 |
86 | proccesPayment() {
87 | console.log(`${this.amount} miqodorda to'lov amalga oshirildi`)
88 | }
89 | }
90 |
91 | /* Ota class Paymentdan bola classga meros beramiz */
92 | class CashPayment extends Payment {
93 | proccesPayment() {
94 | console.log(`${this.amount} naqd pul orqali to'landi.`)
95 | }
96 | }
97 |
98 | class CardPayment extends Payment {
99 | constructor(amount, cardNumber) {
100 | super(amount)
101 | this.cardNumber = cardNumber
102 | }
103 | proccesPayment() {
104 | console.log(`${this.amount} karta orqali to'landi (XXXX-XXXX-XXXX-${this.cardNumber.slice(-4)}).`)
105 | }
106 | }
107 |
108 | class CryptoPayment extends Payment {
109 | constructor(amount, walletAdress) {
110 | super(amount)
111 | this.walletAdress = walletAdress
112 | }
113 |
114 | proccesPayment() {
115 | console.log(`${this.amount} kriptovalyuta orqali to'landi ${this.walletAdress}.`)
116 | }
117 | }
118 |
119 |
120 | let cash = new CashPayment(100)
121 | const card = new CardPayment(250, "1234567812345678")
122 | const crypto = new CryptoPayment(500, "1A2b3C4d5E6f7G8h9I")
123 | console.log(cash,card,crypto)
124 |
--------------------------------------------------------------------------------
/5-dars OOP/javascript/script.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | /* const Product={
3 | init(name,price){
4 | this.name=name
5 | this.price=price
6 | },
7 | getInfo(){
8 | console.log(`${this.name} narxi ${this.price}$`)
9 | }
10 | }
11 |
12 | const ElectronicProduct=Object.create(Product)
13 | ElectronicProduct.initElectronic=function(name,price,brand){
14 | this.init(name,price)
15 | this.brand=brand
16 | }
17 | ElectronicProduct.initElectronic('MacBook Pro',1500,'Apple')
18 | ElectronicProduct.getInfo()
19 |
20 |
21 | const phone=Object.create(Product)
22 | phone.init('Iphone 15',1000,'Apple')
23 | phone.getInfo() */
24 | /* another class */
25 | /* class Account {
26 | constructor(owner, currency, pin) {
27 | this.owner = owner
28 | this.currency = currency
29 | this.pin = pin
30 | this.movements = []
31 | this.locale = navigator.language
32 | console.log(`Thanks for opening an acccount ${this.owner}`)
33 | }
34 |
35 | deposit(val){
36 | this.movements.push(val)
37 | }
38 | withdraw(val){
39 | this.movements.push(-val)
40 | }
41 | approveLoan(val){
42 | return true
43 | }
44 | requestLoan(val){
45 | if(this.approveLoan(val)){
46 | this.deposit(val)
47 | console.log(`Loan approved`)
48 | }
49 | }
50 | }
51 | const acc1 = new Account("Sardorbek", "USD", 1111)
52 | console.log(acc1); */
53 |
54 | /* inheretance object create */
55 | /* const PersoProto = {
56 | init(name, age) {
57 | this.name = name
58 | this.age = age
59 | },
60 | calcAge() {
61 | console.log(2025 - this.age)
62 | }
63 | }
64 | // const student=Object.create(PersoProto)
65 |
66 | const StudentProto = {
67 | init(name, age, course) {
68 | PersoProto.init.call(this, name, age)
69 | this.course = course
70 | },
71 |
72 | getInfo() {
73 | console.log(`${this.name} student learning ${this.course}`)
74 |
75 | },
76 | calcYear() {
77 | PersoProto.calcAge.call(this)
78 | }
79 | }
80 | const student1 = Object.create(StudentProto)
81 | student1.init('Sardorbek',22,'Math')
82 | student1.calcYear() */
83 | /*
84 | const Product = {
85 | initt(name, price) {
86 | this.name = name
87 | this.price = price
88 | },
89 | getInfo() {
90 | return `${this.name} narxi ${this.price}$`
91 | }
92 | }
93 |
94 | const ElectronicProduct = Object.create(Product)
95 |
96 |
97 | ElectronicProduct.initElectronic = function (name, price, brand) {
98 | this.initt(name, price)
99 | this.brand = brand
100 | }
101 |
102 | ElectronicProduct.getWarranty = function () {
103 | return `${this.name} brendi: ${this.brand}, 1 yil kafolat bilan`
104 | }
105 |
106 |
107 | const phone = Object.create(ElectronicProduct)
108 | phone.initElectronic('iPhone 15', 12000000, 'Apple')
109 |
110 | console.log(phone.getInfo())
111 | console.log(phone.getWarranty());
112 | */
113 | const input = document.getElementById('input')
114 | const depositBtn = document.getElementById('deposit')
115 | const withdrawbtn = document.getElementById('withdraw')
116 |
117 | class Account {
118 | constructor(owner, currrency, pin, balance) {
119 | this.owner = owner
120 | this.currrency = currrency
121 | this.pin = pin
122 | this.balance = balance
123 | this.movements = []
124 | }
125 |
126 | deposit(amount) {
127 | this.balance += amount
128 | this.movements.push(amount)
129 | }
130 |
131 | withdraw(amount) {
132 | if (amount > this.balance) {
133 | console.log('You have not enough money')
134 | } else {
135 | this.balance -= amount
136 | this.movements.push(-amount)
137 | }
138 | }
139 | }
140 |
141 |
142 | const account1 = new Account('Sardorbek', 'USD', 1111, 1000)
143 |
144 | let info
145 |
146 |
147 | depositBtn.addEventListener('click', function () {
148 | account1.deposit(Number(input.value))
149 | info = account1.movements.filter((item) => {
150 | return item > 0
151 | })
152 | console.log(info)
153 |
154 | })
155 |
156 |
157 | withdrawbtn.addEventListener('click', function () {
158 | account1.withdraw(Number(input.value))
159 | info = account1.movements.filter((item) => {
160 | return item < 0
161 | })
162 | console.log(info)
163 | })
164 |
--------------------------------------------------------------------------------