Skip to content

Commit 9394dcf

Browse files
committed
Getter Setter Properties
1 parent dea86dd commit 9394dcf

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

10_oops/properties_get_set.js

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 chai = new User("chai@chai.com", "chai")
24+
console.log(chai.email)//CHAI@CHAI.COM
25+
console.log(chai.password)//CHAI

0 commit comments

Comments
 (0)