Skip to content

Commit

Permalink
bind
Browse files Browse the repository at this point in the history
  • Loading branch information
justin212407 committed Sep 7, 2024
1 parent 12d1e99 commit bc21502
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 2 deletions.
30 changes: 30 additions & 0 deletions 10_classes_and_oops/bind.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>React</title>
</head>
<body>
<button>Button Clicked</button>
</body>
<script>
class React {
constructor(){
this.library = "React"
this.server = "https://localhost:300"

//requirement
document
.queryselector('button')
.addEventListener('click', this.handleClick)

}
handleClick(){
console.log("Button clicked");
console.log(this);
}
}
const app = new React
</script>
</html>
4 changes: 2 additions & 2 deletions 10_classes_and_oops/call.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function SetUsername(username){
function setUsername(username){
//complex DB calls
this.username = username
console.log("called");
Expand All @@ -11,5 +11,5 @@ function createUser(username, email, password){
this.password = password
}

const chai = new creatUser("coffee", "[email protected]", "12345")
const chai = new createUser("coffee", "[email protected]", "12345")
console.log(coffee);
32 changes: 32 additions & 0 deletions 10_classes_and_oops/inheritance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class User{
constructor(username){
this.username = username
}

logMe(){
console.log(`USERNAME IS ${this.username}`);
}
}
class Teacher extends User{
constructor(username, email, password){
super(username)
this.email = email
this.password - password
}

addCourse(){
console.log(`A new course was added by ${this.username}`);

}
}


const chai = new Teacher("justin", "[email protected]", "123")
chai.addCourse()
const masalaChai = new User("masalaChai")
masalaChai.logMe()

console.log(chai === Teacher);
console.log(chai instanceof User);


42 changes: 42 additions & 0 deletions 10_classes_and_oops/myclasses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// ES6

class User{
constructor(username, email, password){
this.username = username;
this.email = email;
this.password = password
}

// encryptPassword(){
// return `${this.password}abc`
// }
// changeUsername(){
// return `${this.username.toUpperCase()}`
// }

}

// const chai = new User("justin", "[email protected]", "123")
// console.log(chai.encryptPassword());
// console.log(chai.changeUsername());


//behind the scene

function User(username, email, password){
this.username = username;
this.email = email;
this.password = password
}

User.prototype.encryptPassword = function(){
return `${this.password}abc`
}
User.prototype.changeUsername = function(){
return `${this.password}abc`
}


const tea = new User("chai", "[email protected]", "123")
console.log(tea.encryptPassword());
console.log(tea.changeUsername());
25 changes: 25 additions & 0 deletions 10_classes_and_oops/staticprop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class User{
constructor(username){
this.username = username
}
logMe(){
console.log(`Username: ${this.username}`);
}

static createid(){
return `123`
}
}

const justin = new User("Justin")
// console.log(justin.createid())

class Teacher extends User{
constructor(username, email){
super(username)
this.email = email
}
}

const iphone = new Teacher("iphone", "[email protected]")
console.log(iphone.createId());

0 comments on commit bc21502

Please sign in to comment.