Skip to content

Commit 4d27dc1

Browse files
closure added
1 parent 9342c22 commit 4d27dc1

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

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)