-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetter_setter.js
More file actions
30 lines (23 loc) · 944 Bytes
/
getter_setter.js
File metadata and controls
30 lines (23 loc) · 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class User {
constructor(email, password) {
this.email = email;
this.password = password;
}
get email(){
return this._email.toUpperCase()
}
set email(value){
return this._email = value.toUpperCase();
}
get password(){
// return this._password.toUpperCase(); // get the value of the key/property for this to alter the key name (ex:- _password) if we don use than race condition start b/w constructor and getter setter
return `${this._password}sandeep`
}
set password(value){
// this._password = value.toUpperCase(); // set the value of the key?property alter same name as the getter
this._password = value;
}
}
const sandeep = new User("S@sandeep.com", "abc")
console.log(sandeep.password);
console.log(sandeep.email)