-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfullName.js
More file actions
31 lines (26 loc) · 763 Bytes
/
fullName.js
File metadata and controls
31 lines (26 loc) · 763 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
31
function User(fullName) {
this.fullName = fullName;
Object.defineProperties(this, {
firstName: {
get: function() {
return this.fullName.split(" ")[0];
},
set: function(newFirstName) {
this.fullName = newFirstName + " " + this.lastName;
}
},
lastName: {
get: function() {
return this.fullName.split(" ")[1];
},
set: function(newLastName) {
this.fullName = this.firstName + " " + newLastName;
}
}
});
}
var vasya = new User("Vasya Popkin");
console.log(vasya.firstName);
console.log(vasya.lastName);
vasya.lastName = "Sidorov";
console.log(vasya.fullName);