Skip to content

Commit caa7d31

Browse files
committed
wrapping up js
1 parent b114beb commit caa7d31

File tree

5 files changed

+174
-0
lines changed

5 files changed

+174
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class User {
2+
constructor(email, password){
3+
this.email = email;
4+
this.password = password
5+
}
6+
7+
get email(){
8+
return this._email.toUpperCase()
9+
}
10+
set email(value){
11+
this._email = value
12+
}
13+
14+
get password(){
15+
return `${this._password}hitesh`
16+
}
17+
18+
set password(value){
19+
this._password = value
20+
}
21+
}
22+
23+
const hitesh = new User("h@hitesh.ai", "abc")
24+
console.log(hitesh.email);

10_classes_ans_oop/mathpi.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const descripter = Object.getOwnPropertyDescriptor(Math, "PI")
2+
3+
// console.log(descripter);
4+
5+
// console.log(Math.PI);
6+
// Math.PI = 5
7+
// console.log(Math.PI);
8+
9+
const chai = {
10+
name: 'ginger chai',
11+
price: 250,
12+
isAvailable: true,
13+
14+
orderChai: function(){
15+
console.log("chai nhi bni");
16+
}
17+
}
18+
19+
console.log(Object.getOwnPropertyDescriptor(chai, "name"));
20+
21+
Object.defineProperty(chai, 'name', {
22+
//writable: false,
23+
enumerable: true,
24+
25+
})
26+
27+
console.log(Object.getOwnPropertyDescriptor(chai, "name"));
28+
29+
for (let [key, value] of Object.entries(chai)) {
30+
if (typeof value !== 'function') {
31+
32+
console.log(`${key} : ${value}`);
33+
}
34+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const User = {
2+
_email: 'h@hc.com',
3+
_password: "abc",
4+
5+
6+
get email(){
7+
return this._email.toUpperCase()
8+
},
9+
10+
set email(value){
11+
this._email = value
12+
}
13+
}
14+
15+
const tea = Object.create(User)
16+
console.log(tea.email);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function User(email, password){
2+
this._email = email;
3+
this._password = password
4+
5+
Object.defineProperty(this, 'email', {
6+
get: function(){
7+
return this._email.toUpperCase()
8+
},
9+
set: function(value){
10+
this._email = value
11+
}
12+
})
13+
Object.defineProperty(this, 'password', {
14+
get: function(){
15+
return this._password.toUpperCase()
16+
},
17+
set: function(value){
18+
this._password = value
19+
}
20+
})
21+
22+
}
23+
24+
const chai = new User("chai@chai.com", "chai")
25+
26+
console.log(chai.email);

11_fun_with_js/closure.html

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Closure aur chai</title>
7+
</head>
8+
<body style="background-color: #313131;">
9+
<button id="orange">Orange</button>
10+
<button id="green">Green</button>
11+
</body>
12+
13+
<script>
14+
// function init() {
15+
// let name = "Mozilla";
16+
// function displayName() {
17+
// console.log(name);
18+
// }
19+
// displayName();
20+
// }
21+
// init();
22+
23+
// function outer(){
24+
// let username = "hitesh"
25+
// console.log("OUTER", secret);
26+
// function inner(){
27+
// let secret = "my123"
28+
// console.log("inner", username);
29+
// }
30+
// function innerTwo(){
31+
// console.log("innerTwo", username);
32+
// console.log(secret);
33+
// }
34+
// inner()
35+
// innerTwo()
36+
37+
// }
38+
// outer()
39+
// console.log("TOO OUTER", username);
40+
41+
42+
// function makeFunc() {
43+
// const name = "Mozilla";
44+
// function displayName() {
45+
// console.log(name);
46+
// }
47+
// return displayName;
48+
// }
49+
50+
// const myFunc = makeFunc();
51+
// myFunc();
52+
53+
</script>
54+
<script>
55+
// document.getElementById("orange").onclick = function(){
56+
// document.body.style.backgroundColor = `orange`
57+
// }
58+
// document.getElementById("green").onclick = function(){
59+
// document.body.style.backgroundColor = `green`
60+
// }
61+
62+
function clickHandler(color){
63+
// document.body.style.backgroundColor = `${color}`
64+
65+
return function(){
66+
document.body.style.backgroundColor = `${color}`
67+
}
68+
}
69+
70+
document.getElementById('orange').onclick = clickHandler("orange")
71+
document.getElementById('green').onclick = clickHandler("green")
72+
73+
</script>
74+
</html>

0 commit comments

Comments
 (0)