Skip to content

Commit c8f03da

Browse files
committed
added get set through functions notes
1 parent 7922aa4 commit c8f03da

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
function User(email, password){
2+
this._email = email
3+
this._password = password
4+
5+
Object.defineProperty(this, "email", {
6+
get: function(){
7+
return this._email.toUpperCase()
8+
},
9+
set: function(value){
10+
this._email = value
11+
}
12+
})
13+
Object.defineProperty(this, "password", {
14+
get: function(){
15+
return this._password.toUpperCase()
16+
},
17+
set: function(value){
18+
this._password = value
19+
}
20+
})
21+
}
22+
23+
const user = new User("ayush@mail.com", "abc")
24+
console.log(user.email) // AYUSH@MAIL.COM
25+
console.log(user.password); // ABC

0 commit comments

Comments
 (0)