Skip to content

Commit

Permalink
Wrapping up js series
Browse files Browse the repository at this point in the history
  • Loading branch information
hiteshchoudhary committed Jul 22, 2023
1 parent ad503dd commit 9342c22
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
24 changes: 24 additions & 0 deletions 10_classes_and_oop/getter_setter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class User {
constructor(email, password){
this.email = email;
this.password = password
}

get email(){
return this._email.toUpperCase()
}
set email(value){
this._email = value
}

get password(){
return `${this._password}hitesh`
}

set password(value){
this._password = value
}
}

const hitesh = new User("[email protected]", "abc")
console.log(hitesh.email);
34 changes: 34 additions & 0 deletions 10_classes_and_oop/mathpi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const descripter = Object.getOwnPropertyDescriptor(Math, "PI")

// console.log(descripter);

// console.log(Math.PI);
// Math.PI = 5
// console.log(Math.PI);

const chai = {
name: 'ginger chai',
price: 250,
isAvailable: true,

orderChai: function(){
console.log("chai nhi bni");
}
}

console.log(Object.getOwnPropertyDescriptor(chai, "name"));

Object.defineProperty(chai, 'name', {
//writable: false,
enumerable: true,

})

console.log(Object.getOwnPropertyDescriptor(chai, "name"));

for (let [key, value] of Object.entries(chai)) {
if (typeof value !== 'function') {

console.log(`${key} : ${value}`);
}
}
16 changes: 16 additions & 0 deletions 10_classes_and_oop/object_get_set.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const User = {
_email: '[email protected]',
_password: "abc",


get email(){
return this._email.toUpperCase()
},

set email(value){
this._email = value
}
}

const tea = Object.create(User)
console.log(tea.email);
26 changes: 26 additions & 0 deletions 10_classes_and_oop/properties_get_set.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function User(email, password){
this._email = email;
this._password = password

Object.defineProperty(this, 'email', {
get: function(){
return this._email.toUpperCase()
},
set: function(value){
this._email = value
}
})
Object.defineProperty(this, 'password', {
get: function(){
return this._password.toUpperCase()
},
set: function(value){
this._password = value
}
})

}

const chai = new User("[email protected]", "chai")

console.log(chai.email);

0 comments on commit 9342c22

Please sign in to comment.