Skip to content

Commit 3020898

Browse files
committedJun 10, 2024
feat: add color changer project
1 parent bdfc4b6 commit 3020898

File tree

6 files changed

+85
-41
lines changed

6 files changed

+85
-41
lines changed
 

‎.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"cSpell.words": ["Brijesh", "Chavda", "Eich", "iambrijeshtoo"],
2+
"cSpell.words": ["Brijesh", "Chavda", "Eich", "iambrijeshtoo", "Monaspace"],
33
"editor.tokenColorCustomizations": {
44
"comments": "",
55
"textMateRules": []

‎15_this_keyword/1_this_keyword.js

+55-34
Original file line numberDiff line numberDiff line change
@@ -4,59 +4,80 @@
44
// - In JavaScript, the this keyword refers to an current context.
55

66
// Note
7-
// - The this keyword refers to different objects depending on how it is used:
8-
// 1. Alone -> Global object
9-
// 2. In a object method -> object
10-
// 3. In a function -> Global object
11-
// 4. In a function with strict mode ("use strict") -> undefined
12-
// - In an event, this refers to the element that received the event.
13-
// - Methods like call(), apply(), and bind() can refer this to any object.
14-
15-
// 1. Alone -> Global object
7+
// The this keyword refers to different objects depending on how it is used:
8+
// 5. Arrow function and `this` keyword (Not Recommended) -> See the code example below
9+
// 6. In a function with strict mode ("use strict") -> undefined
10+
// TODO: In an event, this refers to the element that received the event.
11+
// TODO: Methods like call(), apply(), and bind() can refer this to any object.
12+
13+
// 1. this -> Alone -> Global object
1614
console.log(this);
1715

18-
// 2. In a object method -> object
16+
// Regular function & `this` keyword
17+
18+
// 2. this -> In object method (regular function) -> Current Object
1919
const object = {
20-
key1: "Value1",
21-
key2: "Value2",
22-
key3: function () {
23-
console.log(this.key1);
20+
key: "value",
21+
method: function () {
22+
console.log(this);
23+
console.log(this.key);
2424
},
2525
};
26-
console.log(object.key3());
26+
console.log(object.method());
2727

28-
// 3. In a function -> Global object
29-
function iAmFunction() {
28+
// 3. this -> In regular function -> Global object
29+
function regularFunction() {
3030
return console.log(this);
3131
}
32+
console.log(regularFunction());
3233

33-
console.log(iAmFunction());
34-
35-
// 4. Function inside function -> Global object
36-
function iAmOutsideFunction() {
37-
function iAmInsideFunction() {
34+
// 4. this -> Function inside function -> Global object
35+
function outerRegularFunction() {
36+
function innerRegularFunction() {
3837
return console.log(this);
3938
}
40-
console.log(iAmInsideFunction());
39+
console.log(innerRegularFunction());
4140
}
42-
console.log(iAmOutsideFunction());
41+
console.log(outerRegularFunction());
4342

44-
// 5. Arrow function and this keyword
45-
// - Arrow functions have a different behavior with this. They inherit the this value from the enclosing scope where they are defined, not from how they are called.
43+
// Arrow function & `this` keyword
44+
45+
// Note
46+
// - Never use the arrow function inside method or constructor.
47+
48+
// 5. this -> In object method (arrow function) -> Global object
49+
const object1 = {
50+
key: "value",
51+
method: () => {
52+
return console.log(this);
53+
},
54+
};
55+
console.log(object1.method());
4656

47-
// Defined in the Global Scope -> Global object
57+
// 6. this -> In arrow function -> Global object
4858
const arrowFunction = () => {
4959
return console.log(this);
5060
};
5161
console.log(arrowFunction());
5262

53-
// Defined Inside a Function or Object
54-
const object1 = {
55-
key1: "value1",
56-
key2: "value2",
57-
key3: () => {
63+
// 7. this -> Arrow function inside arrow function -> Global object
64+
const outerArrowFunction = () => {
65+
const innerArrowFunction = () => {
5866
console.log(this);
59-
},
67+
};
68+
console.log(innerArrowFunction());
6069
};
70+
console.log(outerArrowFunction());
71+
72+
// If you are thinking that. If `this` keyword is always refer to global object. Why can't we just rap the object around it. Then it will sure stop referring to global object.
6173

62-
console.log(object1.key3());
74+
const outerObject = {
75+
key1: "value",
76+
innerObject: {
77+
arrowFunction: () => {
78+
console.log(this.key1);
79+
},
80+
},
81+
};
82+
console.log(outerObject.innerObject.arrowFunction());
83+
// `this` just doesn't care. It won't show the key1's -> va lue.

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,4 @@
142142
2. Call back hell
143143
2. Asynchronous programming
144144
1. setTimeout()
145-
2. setInterval()
145+
2. setInterval()

‎code_test_space.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
// console.log(a);
2-
// var a = 10;
3-
4-
console.log(b);
5-
let b = 10;
1+
// TODO: This example is connected to the closer concept which is the video number - 49.
2+
// function outerRegularFunction() {
3+
// const variable = "value";
4+
// function innerRegularFunction() {
5+
// console.log(this.variable);
6+
// }
7+
// console.log(innerRegularFunction());
8+
// }
9+
// console.log(outerRegularFunction());

‎notes/monospace_font.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
1. There should be different between smaller and capital letter height.
2+
2. Good render quality
3+
3. No pixelation
4+
4. Not too comic
5+
5. Not too cursive
6+
6. Not too narrow
7+
7. Not too wide
8+
8. Not too small
9+
9. Not too highted
10+
11+
# Top Fonts
12+
13+
1. Monaspace Neon
14+
2. Fira Code
15+
3. Source Code Pro
16+
4. Hack
17+
5. JetBrains Mono
18+
6. MonoLisa
19+
7. Cascadia Code

‎project/1_color_changer/index.html

Whitespace-only changes.

0 commit comments

Comments
 (0)
Please sign in to comment.