Skip to content

Commit c271506

Browse files
committed
advance javascript done
1 parent 5365d88 commit c271506

File tree

12 files changed

+422
-1
lines changed

12 files changed

+422
-1
lines changed

09_advance_One/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ <h1>ajax programing</h1>
2525
// d8 folder must see line 104
2626
// console.log(XMLDocument);
2727
// console.log(XMLHttpRequest);
28-
const requestUrl = "https://api.github.com/users/hiteshchoudhary";
28+
const requestUrl = "https://api.github.com/users/wcoder547";
2929
const xhr = new XMLHttpRequest();
3030
xhr.open("GET", requestUrl);
3131
xhr.onreadystatechange = function () {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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>React</title>
7+
</head>
8+
<body>
9+
<button>button clicked</button>
10+
</body>
11+
<script>
12+
console.log("dr mashoor gulati is speaking");
13+
class React {
14+
constructor() {
15+
this.library = "React";
16+
this.server = "https://localhost:3000";
17+
document
18+
.querySelector("button")
19+
.addEventListener("click", this.hadnleclick.bind(this));
20+
}
21+
22+
hadnleclick() {
23+
console.log("this button is clicked");
24+
console.log(this); //before bind this present the context in which this calling wich means that button it return a button ..
25+
//but after giving bind(this) this context change and it give us complete class ...
26+
}
27+
}
28+
29+
const app = new React();
30+
</script>
31+
</html>

10_object_oriented_programing/call.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function setUserName(username) {
2+
//console.log("called");
3+
// console.log(this);
4+
this.username = username;
5+
}
6+
function createUser(username, email, password) {
7+
setUserName.call(this, username);
8+
this.email = email;
9+
this.password = password;
10+
}
11+
12+
const chai = new createUser("waseemakram", "mw5667155@gmail.com", 123);
13+
14+
console.log(chai);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// // //ES6
2+
// // console.log("is js working")
3+
4+
// class user {
5+
// constructor(username, email, password) {
6+
// this.username = username;
7+
// this.email = email;
8+
// this.password = password;
9+
// }
10+
11+
// encrytPassword() {
12+
// return `${this.password}abc`;
13+
// }
14+
// changeUserName() {
15+
// return `${this.username.toUpperCase()}`;
16+
// }
17+
// }
18+
19+
// const fc1 = new user("wcoder547", "malik@gmail.com", 234);
20+
// console.log(fc1.changeUserName());
21+
// console.log(fc1.encrytPassword());
22+
23+
//behind the scenes
24+
25+
function user(username, email, password) {
26+
this.username = username;
27+
this.email = email;
28+
this.password = password;
29+
}
30+
31+
user.prototype.encrytPassword = function () {
32+
return `${this.password}abc`;
33+
};
34+
user.prototype.changeUserName = function () {
35+
return `${this.username.toUpperCase()}`;
36+
};
37+
38+
const fc2 = new user("waseemmalik547", "hafiz@gmail.com", 234);
39+
console.log(fc2.encrytPassword());
40+
console.log(fc2.changeUserName());
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// console.log("this is user1");
2+
3+
class user {
4+
constructor(username, password) {
5+
this.username = username;git
6+
this.password = password;
7+
}
8+
get password() {
9+
return this._password.toUpperCase();
10+
}
11+
set password(value) {
12+
this._password = value;
13+
}
14+
}
15+
const user1 = new user("waseem", 123);
16+
console.log(user.password);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//=========================INHERITANCE ========================
2+
3+
class user {
4+
constructor(username) {
5+
this.username = username;
6+
}
7+
logIn() {
8+
console.log(`the user login is : ${this.username}`);
9+
}
10+
}
11+
12+
class Teacher extends user {
13+
constructor(username, email, password) {
14+
super(username);
15+
this.email = email;
16+
this.password = password;
17+
}
18+
addCourse() {
19+
console.log(`this course is added by : ${this.username}`);
20+
}
21+
}
22+
23+
const teach1 = new Teacher("coffee", "coffee@gmail.com", 123);
24+
teach1.addCourse();
25+
teach1.logIn();
26+
27+
const us1 = new user("vin252");
28+
us1.logIn();
29+
30+
console.log(teach1 === us1); //false
31+
console.log(us1 === user); //false
32+
console.log(us1 instanceof user); //true
33+
console.log(teach1 instanceof Teacher); //True..
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// console.log("is js working");
2+
3+
const desc = Object.getOwnPropertyDescriptor(Math, "PI");
4+
//console.log(desc);
5+
/*
6+
{
7+
value: 3.141592653589793,
8+
writable: false,
9+
enumerable: false,
10+
configurable: false
11+
}
12+
*/
13+
14+
const intro = {
15+
name: "waseemakram",
16+
skill: "developer",
17+
isAvailable: true,
18+
anythingElse: function () {
19+
console.log("nothing is remaining");
20+
},
21+
};
22+
23+
// const intro1 = Object.getOwnPropertyDescriptor(intro, "name");
24+
// console.log(intro1);
25+
/*
26+
{
27+
value: 'waseemakram',
28+
writable: true,
29+
enumerable: true,
30+
configurable: true
31+
}
32+
*/
33+
34+
Object.defineProperty(intro, "name", {
35+
writable: false,
36+
enumerable: false,
37+
});
38+
39+
const intro1 = Object.getOwnPropertyDescriptor(intro, "name");
40+
//console.log(intro1);
41+
/*
42+
{
43+
value: 'waseemakram',
44+
writable: false,
45+
enumerable: false,
46+
configurable: true
47+
}
48+
*/
49+
50+
// for (let [key, values] of intro) {
51+
// console.log(`Key : ${key} values : ${values}`);
52+
// } //TypeError: intro is not iterable
53+
54+
for (let [key, values] of Object.entries(intro)) {
55+
if (typeof values !== "function") {
56+
console.log(`Key : ${key} values : ${values}`);
57+
}
58+
}
59+
60+
/*
61+
name ni aya q ke hmne usko enumerable false kr dia tha ...is wja se wo iterate ni hoga
62+
Key : skill values : developer
63+
Key : isAvailable values : true
64+
*/
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# javascript and classes
2+
3+
## OOP
4+
5+
## object
6+
7+
-collection of properties and methods
8+
-toLowercase()
9+
10+
## why use OOP
11+
12+
-for DRY (don't repeat yourself)
13+
14+
## parts of OOp
15+
16+
object literal
17+
18+
-constructor function
19+
-prototypes
20+
-classes
21+
22+
- instances (new,this )
23+
24+
## 4 pillars
25+
26+
Abstraciton ---(just like fetch ..chze behind the scene ho rhi hoti chupa leta he chze )
27+
Encapsulation (wrap up the data ...hide the data ...private or public )
28+
Inheritance
29+
Polymorphism (Many roops )
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
function multiply(num) {
2+
return num * 5;
3+
}
4+
//console.log(multiply(5)); //25
5+
multiply.power = 2;
6+
//console.log(multiply.power); //2
7+
//console.log(multiply.prototype); //{}
8+
//IMP : javascript me hr chz object hoti he Almost ..function function bhi he sth object bhi he
9+
//Function-> object->null
10+
//array-> object-> null
11+
// string -> object ->null
12+
13+
function createUser(username, score) {
14+
this.username = username;
15+
this.score = score;
16+
}
17+
createUser.prototype.increment = function () {
18+
this.score++;
19+
};
20+
createUser.prototype.printMe = function () {
21+
console.log(`Score: ${this.score}`);
22+
};
23+
24+
const tea = new createUser("Tea", 255);
25+
const coffe = new createUser("coffee", 455);
26+
console.log(tea); //object pore ka pora object hme mil gya he return
27+
tea.printMe();
28+
coffe.increment(); //cofee ki value ko increment kre ga .
29+
console.log(coffe); // ab pora object return kre ga and the coffe value is 455+1=456..
30+
31+
/* =============Notes About New Keyword ====================
32+
33+
Here's What happens behind the scenes when new keyword is used :
34+
35+
-> A new object is created: the new keyword initiates the creation of the new javascript object .
36+
37+
-> A Prototype is linked : the newly created object gets linked to the prototype property of the constructor function .
38+
this means it has the access to properties and methods defined on the constructor 's prototype.
39+
40+
-> The constructor is called : the constructor function is called with the specified arguments and this is bond to
41+
the newly created object . if no explict return value is specified from the constructor javascript assume this ,
42+
newly created object to be intended return value .
43+
44+
-> The new object is returned: After the constructor function has been called , if it does not return a non-premitive value
45+
(object,fucntion ,array etc). the newly created object is returned
46+
47+
48+
*/

10_object_oriented_programing/oop.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//===========================Object literal=========================
2+
3+
const user = {
4+
name: "waseem akram",
5+
isLoggedIn: true,
6+
loggedincount: 8,
7+
8+
getUserDetails: function () {
9+
console.log("user data is coming from database");
10+
console.log(this);
11+
console.log(`hello :${this.name}`);
12+
},
13+
};
14+
15+
//console.log(user.loggedincount);
16+
//console.log(user.getUserDetails());
17+
//console.log(this); //{}
18+
19+
//==============constructor function===============
20+
21+
// function Loggin(username, password) {
22+
// this.username = username;
23+
// this.password = password;
24+
// return this;
25+
// }
26+
// const userOne = Loggin("wcoder547", "123");
27+
// const userTwo = Loggin("fahad547", "456"); //it will override the values ....
28+
// console.log(userOne);
29+
// console.log(userTwo);
30+
31+
function Loggin(username, password) {
32+
this.username = username;
33+
this.password = password;
34+
}
35+
const userOne = new Loggin("wcoder547", "123");
36+
const userTwo = new Loggin("fahad547", "456"); //it will override the values ....
37+
//console.log(userOne);
38+
//console.log(userTwo);
39+
40+
console.log(userOne.constructor); //return function
41+
42+
console.log();
43+
44+
//IMPORTANT ABOUT NEW KEYWORD ..
45+
//step1:sbse phle ik empty object{} create hota he jisko instance bola jata he .
46+
47+
//step2: constructor function called through new...
48+
49+
//step-3 : this keyword inject in this
50+
51+
//step 4 : end pe hme mil jate he ..

0 commit comments

Comments
 (0)